Frederick Cheung wrote:
> On Feb 23, 7:17�pm, Max Williams <[email protected]> wrote:
>>
>> has_many :quiz_questions, :order => "#{self[:style] == sequential ?
>> 'position' : 'low_band'}"
>>
> 
> The order clause is an sql fragment, so you can't do quite what you've
> written.
> You can of course write an if statement in sql (although you would
> have to also join the parent table), and order by something like
> IF(foo = 'bar', position, low_band)
> 
> This wouldn't end up as a very efficient query though and feels quite
> nasty.
> 
> 
> Fred

yeah, i'm inclined to agree re the nasty.  It does work though:  in case 
anyone else stumbles across this, i have

  has_many :quiz_questions, :dependent => :destroy, :include => [:quiz], 
:order => "IF(quizzes.style = 'sequential', position, low_band)"

The extra include is the dodgy bit isn't it.  I'll give it a go anyway.

Thanks!
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to