class Foo < ActiveRecord::Base
has_many :bar
end
class Bar < ActiveRecord::Base
belongs_to :foo
end
I'd like to order my :foos... based on its last :bar
So, let's say:
Foo.first.bars => [{key: 'a', value: 1}, {key: 'b', value: 2}, {key: 'c', value: 3}]
So... Foo.first.bars.last.value => 3
I have a bunch of :foos, each having a bunch of :bars, but I only care about the last :bar.
Can I sort my :foos based on its last :bars value
? Would Bar need a scope?
For instance...
Foo.includes(:bars).order('bars.last.value')