ruby-on-railssearchlogic

RoR: Search Logic: How do I do a left join, instead of the default left inner join?


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.


Solution

  • 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