0

I'm doing sorting based on a field that references another table (and sorting on that other table's 'name' field). The issue is that when my first set of objects has some entries that don't have a reference to the other, that entry is excluded from the sorting.

So.. in short, I have a column that is a reference to another table (and sorting over a column in that table), but I also want to include null references.

NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352

1 Answers1

1

I am not 100% sure I understand your question, but for example, when you write a named_scope you can pass options like this:

named_scope descend_it_by_that_other_column, 
:select => "",
:joins => "LEFT JOIN ...", 
:conditions => "..."

another example:

def my_fancy_method_returning_things
 association_name.all :limit => 5, :joins => 'LEFT JOIN ... ON ... = ...', :order => ...'
end
socjopata
  • 5,028
  • 3
  • 30
  • 33
  • ah, I didn't think of overriding the named scope. I'll try that in a bit. thanks. – NullVoxPopuli Aug 09 '11 at 13:28
  • 1
    If you use searchlogic and have something like this in your params: "search" => { "order"=>"ascend_by_rating" } then searchlogic will use ascend_by_rating named scope if defined. I hope this helps :) – socjopata Aug 09 '11 at 13:49