You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Joe Baldwin <jf...@earthlink.net> on 2010/02/19 20:39:03 UTC

Relationship & Sort Ordering

I need to sort-order a list returned from a to-many relationship.  It is logical that this ordering be applied in all cases.

Question:
Is there a simple way to apply this by modifying the SelectQuery associated with the relationship or should I just sort order the list each time it is returned?

(If I missed it in the docs please send me a link.)

Thanks,
Joe


Re: Relationship & Sort Ordering

Posted by Joe Baldwin <jf...@earthlink.net>.
Hi Andrey,

> Proposal link:
> http://markmail.org/message/6psmcz6zfcb6fj7g

Yes this is exactly what I was thinking of!


"but this will not work for flattened rels. So we'll need either add orderings for each component of the path (I don't like this way) or add orderings for DbRels as well:
	DbRelationship paintingsArray = ...
	paintingsArray.addOrdering(new Ordering("PAINTING_NAME",
	SortOrder.ASCENDING)); //notice db attr name

Then Obj rel will automatically pick orderings from underlying Db Rel(s)"

I am not completely following your comment about the flattened relationship. Howeve, IMHO it seems logical to implement any SelectQuery/SQL customization as an extension of the DbRelationship (as you comment) and also allow it to be added via the CayenneModeler (so that webapps with variable entry points will be supported).

Thanks for your help,
Joe





On Feb 19, 2010, at 3:21 PM, Andrey Razumovsky wrote:

> Proposal link:
> http://markmail.org/message/6psmcz6zfcb6fj7g
> 
> 2010/2/19 Andrey Razumovsky <ra...@gmail.com>
> 
>> Hi,
>> 
>> Unfortunately this is not yet supported. See
>> http://issues.apache.org/jira/browse/CAY-477.
>> You'll need to order list every time it is returned (e.g. using
>> Ordering.orderList())
>> 
>> 2010/2/19 Joe Baldwin <jf...@earthlink.net>
>> 
>> I need to sort-order a list returned from a to-many relationship.  It is
>>> logical that this ordering be applied in all cases.
>>> 
>>> Question:
>>> Is there a simple way to apply this by modifying the SelectQuery
>>> associated with the relationship or should I just sort order the list each
>>> time it is returned?
>>> 
>>> (If I missed it in the docs please send me a link.)
>>> 
>>> Thanks,
>>> Joe
>>> 
>>> 
>> 
>> 
>> --
>> Andrey
>> 
> 
> 
> 
> -- 
> Andrey


Re: Relationship & Sort Ordering

Posted by Andrey Razumovsky <ra...@gmail.com>.
Proposal link:
http://markmail.org/message/6psmcz6zfcb6fj7g

2010/2/19 Andrey Razumovsky <ra...@gmail.com>

> Hi,
>
> Unfortunately this is not yet supported. See
> http://issues.apache.org/jira/browse/CAY-477.
> You'll need to order list every time it is returned (e.g. using
> Ordering.orderList())
>
> 2010/2/19 Joe Baldwin <jf...@earthlink.net>
>
> I need to sort-order a list returned from a to-many relationship.  It is
>> logical that this ordering be applied in all cases.
>>
>> Question:
>> Is there a simple way to apply this by modifying the SelectQuery
>> associated with the relationship or should I just sort order the list each
>> time it is returned?
>>
>> (If I missed it in the docs please send me a link.)
>>
>> Thanks,
>> Joe
>>
>>
>
>
> --
> Andrey
>



-- 
Andrey

Re: Relationship & Sort Ordering

Posted by Andrey Razumovsky <ra...@gmail.com>.
Hi,

Unfortunately this is not yet supported. See
http://issues.apache.org/jira/browse/CAY-477.
You'll need to order list every time it is returned (e.g. using
Ordering.orderList())

2010/2/19 Joe Baldwin <jf...@earthlink.net>

> I need to sort-order a list returned from a to-many relationship.  It is
> logical that this ordering be applied in all cases.
>
> Question:
> Is there a simple way to apply this by modifying the SelectQuery associated
> with the relationship or should I just sort order the list each time it is
> returned?
>
> (If I missed it in the docs please send me a link.)
>
> Thanks,
> Joe
>
>


-- 
Andrey

Re: Relationship & Sort Ordering

Posted by Joe Baldwin <jf...@earthlink.net>.
Lucas,

It looks like your example is the standard way to perform sort-ordering on a SelectQuery.

In the scenario I am working on, I have a CayenneDataObject that has a to-many relationship that the obj returns as a list.  The list is created as the result of what I presume is some sort of SelectQuery auto-generated by Cayenne.

Currently I am doing "in-memory sorting of lists" described in the "Using Orderings" section of the Cayenne Guide.  

This is working quite well, but I realized that the toMany list should be sorted in all cases.  Therefore I was wondering if Cayenne has a way to modify what I assume is the auto-generated SelectQuery associated with the relationship so that it can be applied in all cases.

Thanks,
Joe





On Feb 19, 2010, at 2:44 PM, Lucas Holt wrote:

> Joe Baldwin wrote:
>> I need to sort-order a list returned from a to-many relationship.  It is logical that this ordering be applied in all cases.
>> 
>> Question:
>> Is there a simple way to apply this by modifying the SelectQuery associated with the relationship or should I just sort order the list each time it is returned?
>> 
>> (If I missed it in the docs please send me a link.)
>> 
>> Thanks,
>> Joe
>> 
>>  
> 
> Look at the documentation on "orderings".  For cayenne 3,
> 
>           final SelectQuery query = new SelectQuery( Company.class );
>           query.setPageSize( 50 );
>           query.addOrdering( "companyName", SortOrder.ASCENDING );
>           final List<Company> c = dataContext.performQuery( query );
> 
> Lucas


Re: Relationship & Sort Ordering

Posted by Lucas Holt <lu...@foolishgames.com>.
Joe Baldwin wrote:
> I need to sort-order a list returned from a to-many relationship.  It is logical that this ordering be applied in all cases.
>
> Question:
> Is there a simple way to apply this by modifying the SelectQuery associated with the relationship or should I just sort order the list each time it is returned?
>
> (If I missed it in the docs please send me a link.)
>
> Thanks,
> Joe
>
>   

Look at the documentation on "orderings".  For cayenne 3,

            final SelectQuery query = new SelectQuery( Company.class );
            query.setPageSize( 50 );
            query.addOrdering( "companyName", SortOrder.ASCENDING );
            final List<Company> c = dataContext.performQuery( query );

Lucas