cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <mgen...@masslight.net>
Subject Re: Selecting relationships without restriction
Date Mon, 07 Nov 2011 14:20:47 GMT
Hi Christian,

As others pointed out, getPrices() will return all of the prices.
What I usually do for things like this is write a helper method to
filter the historic ones out.  Create a getCurrentPrices() which
returns calls getPrices() and filters based upon historic = true and
return a new list.

mrg


On Sun, Nov 6, 2011 at 11:04 AM, Christian Grobmeier
<grobmeier@gmail.com> wrote:
> Hi all,
>
> I have two tables Article and Price.
> The table Price can containt historic prices which should not be selected.
>
> I do something like that:
>
> Expression expression = ExpressionFactory.matchExp("prices.historic", false);
> Expression fullExp =
> expression.orExp(ExpressionFactory.matchExp("prices+.historic",
> null));
> SelectQuery query = new SelectQuery(Module.class, fullExp);
> List list = ctx.performQuery(query);
>
> This generates a correct sql like:
>
> SELECT DISTINCT t0....*
> FROM articles t0
> LEFT JOIN prices t1 ON (t0.id = t1.article_id)
> WHERE (t1.historic = false) OR (t1.historic IS NULL)
>
> Using that sql works well on my MySQL db directly.
>
> When I run Cayenne, my junit test case fails because I when I call
> getPrices() I get even the historic ones.
>
> For example:
>
> List list = ctx.performQuery(query);
> Article a = (Article)list.get(0);
> a.getPrices(); // <--- returns historic true/false
>
> I had the expectation that the historic prices should not appear here.
> Do I miss something?
>
> Cheers,
> Christian
>

Mime
View raw message