1

Lets says we have Films and HeaderItems. Sometimes a Film has a HeaderItem linked to it OneToOne but not always.

Now I want to sort all the Films on their title BUT I would like the films with a HeaderItem linked to them to sort on HeaderItem.Position (if HeaderItem is not null).

I've tried to implement a OneToMany on Films and a OneToOne but I can get the sorting to work. He can't convert the QueryExpression to String or vice versa.

Any ideas on how to do this?

2
  • So it has to be sorted first by HeaderItem.Position (if it exists), and then by Title? This would mean that all records with a HeaderItem would come first. Sep 17, 2009 at 12:21
  • Yup, that would be the general idea. Sep 17, 2009 at 12:23

2 Answers 2

1

Ok, I figured it out.

First things first, I changed the relation between Film and HeaderItem to a OneToMany.

Then I used

Film.OrderedList("$ISNULL(HeaderItem.ShowOnTopInCategory, 0)-, Top10, MovieTitle");

to get a list of films order by headerItems first and then the rest.

Works great. Btw, the $-sign in front of the ISNULL avoids the ISNULL from being replaced by the CoolStorage SQL parser.

0

I haven't tried it, but this may actually work:

  Film.List().OrderedBy("HeaderItem.Position,Title");

If that doesn't work, I'm afraid you'll have to create a view or execute ad-hoc SQL using CASE statements in your ORDER BY clause.

1
  • Ok, this works fine BUT in another query we can't only select the Films that have a HeaderItem now. the HAS or IS NOT NULL don't work. Sep 17, 2009 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.