Re: orderby on tomany relation

From: Holger Hoffstätte (holge..izards.de)
Date: Fri Mar 18 2005 - 11:57:05 EST

  • Next message: Andrus Adamchik: "Re: orderby on tomany relation"

    Jürgen Saar wrote:
    > is there a way to define a default ordering
    > for a relation?

    As Andrus wrote this feature is often required (last week, IIRC?) and -
    when 'done right' can save a lot of manual coding, not to mention the
    possibilities for inconsistencies, model/view mish-mash etc. Unfortunately
    the problem is not really difficult, but simply affects many different
    parts of Cayenne:

    - it is not enough to order the relationship array after fetching; you
    really, really want to keep this list ordered even when you're
    adding/removing objects. Long ago I wrote a SortedList implementation
    exactly for this purpose (which was quite difficult since the
    List/Collections contracts are sloppy and partially contradictory) and
    contributed it to Cayenne but since I didn't keep up with development I
    don't know where this currently floats around. Send me an email if you
    need it. Right now I'm not even using Cayenne. :(

    - writing additional cover methods that do the required ordering kind of
    works, but is IMHO really just a band-aid and sooner or later will create
    unpleasant inconsistencies. You _will_ forget to call the manual sorting
    somewhere.

    - such a feature is not really useful without Modeler support. Ideally you
    would select either an ObjEntity or a relationship, check an "ordered"
    checkbox and set up a list of orderings by attribute (e.g. ascending by
    name, descending by rank etc.). Simply slapping Comparable onto the
    ObjEntity class is not helpful since you still need to generate the ORDER
    BY statements mapped to the correspondig DbAttributes; otherwise you
    wouldn't get any server-side sorting, which was the whole point of the
    idea. ;-)
    The Modeler-generated orderings would still be available (and required for
    insertions/removals) on the object level via an automatically generated
    Comparator and addition of Comparable to the generated class.

    One really should not have to write any application code for this.

    Holger



    This archive was generated by hypermail 2.0.0 : Fri Mar 18 2005 - 11:57:08 EST