Re: orderby on tomany relation

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Mar 18 2005 - 12:43:15 EST

  • Next message: Bryan Lewis: "Re: Foreign keys"

    Hi Holger,

    What I disagree with (and disagreed in the past) is that a difficulty with
    a 100% solution should prevent us from releasing a partial, but still very
    useful sorting of relationships during fetch.

    Ordering is mainly used for display purposes and many of the cases are
    read-only. So it will be helpful right away to a lot of users. As we go we
    can improve it, e.g. adding ordering refresh hook on commit.

    Andrus

    > 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 - 12:43:18 EST