I have the following two models:
class Shelf < ActiveRecord::Model
has_many :wines
def self.order_by_oldest_bottle_of_wine
#TODO: order by the oldest wine bottle...
end
end
class Wine < ActiveRecord::Model
belongs_to :shelf
attr_accessible :produce_date
end
In the shelf model, I want to order shelfs by the oldest wine bottle on the shelf (i.e. shelf with the oldest wine bottle first), but not 100% sure of the implementation.
Many Thanks,
If you are using Rails 3.x you can use any one of the following
Solution 1:
Solution 2: If you want to use scope