Kind of a complex find :order ...


i ve got two models,
"Question" and "Answer"
A "question" can have many "answers", or none.

I want to order my questions by answers date or question date if it
has no answer,
i tried to do that :

Question.find(:all, :order=>" DESC, DESC")

But questions without answers appear always after questions with
answers, even when the question was created after an answer..

Could you give me an hints ?

Thanks a lot..

I think for this I would find all the questions (and eager load the
answers for those questions) and then sort the array. e.g.

class Question < ActiveRecord::Base
  has_many :answers, :order => " DESC"

  def latest_date_including_answers
    if self.answers.blank?

  def self.newest_including_answers
    find(:all, :include => :answers).sort{|a,b|
      a.latest_date_including_answers <=>

The latest_date_including_answers method assumes that answers always
come after the question is asked (since it doesnt compare