searchlogic icon indicating copy to clipboard operation
searchlogic copied to clipboard

Order by association field

Open graywh opened this issue 15 years ago • 0 comments

Ordering by a field on an association omits records missing that association because it's not a left join.

class Model < ActiveRecord::Base belongs_to :parent, :class_name => 'Model', :foreign_key => 'parent_id' end

fb = Model.create(:name=>'FooBar') Model.create(:name=>'Foo', :parent=>fb) Model.create(:name=>'Bar', :parent=>fb) Model.count #=> 3 Model.ascend_by_parent_name.count #=> 2

Just a tad bit annoying.

graywh avatar May 17 '10 14:05 graywh