cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <mgen...@masslight.net>
Subject Re: Counting the number of destination objects for a to-many relationship (or checking if empty)
Date Mon, 29 Feb 2016 18:09:37 GMT
PS. I think the code works correctly, but let me know if it doesn't.


On Mon, Feb 29, 2016 at 1:09 PM, Michael Gentry <mgentry@masslight.net>
wrote:

> Hi Hugi,
>
> I'm not sure if this will work for 4.0 (since earlier you said you are
> using it), but this is what I'd use for 3.1:
>
>
> https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/utilities/AggregateUtils.java
>
> If you have A->>B, you'd construct a SelectQuery to fetch B's where toA =
> your A object.  Basically, invert your query and count the matches.
> Something like:
>
> SelectQuery selectQuery = new SelectQuery(B.class);
> selectQuery.setQualifier(ExpressionFactory.matchExp("toA", a));
> int countOfB = AggregateUtils.count(dataContext, selectQuery);
>
> Some other example uses:
>
>
> https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/Aggregates.java
>
> mrg
>
>
> On Mon, Feb 29, 2016 at 7:25 AM, Hugi Thordarson <hugi@karlmenn.is> wrote:
>
>> Hi all,
>>
>> Is there any simple way or me to count the number of destination objects
>> of a to-many relationship? (without fetching) If not, is there some way to
>> generate an expression from a relationship, so I can use that expression in
>> my own counting functions?
>>
>> Cheers,
>> - hugi
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message