I'd like the change the order field in a has_many relationship based on
the value of one of my other fields.  Is this possible?

In this case my parent model is Quiz and the child is QuizQuestion.  If
a quiz's 'style' attribute is set to 'sequential' i'd like to get
@quiz.questions back in order of quiz_questions.position, otherwise i'd
like to get them back in order of quiz_questions.low_band.

So, something like the following (i know this doesn't work because self
is the class here)

has_many :quiz_questions, :order => "#{self[:style] == sequential ?
'position' : 'low_band'}"

can i use a proc to set the order for example?

thanks, max
-- 
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