1
我有一個簡單許多一對多ER說明如下:查詢(M:N)由關係有序屬性
型號order.rb:
class Order < ActiveRecord::Base
has_many :cronologies
has_many :statuses, :through => :cronologies
end
型號cronology.rb:
class Cronology < ActiveRecord::Base
belongs_to :order
belongs_to :status
validates_uniqueness_of :order_id, :scope => :status_id
end
型號status.rb:
class Status < ActiveRecord::Base
has_many :cronologies
has_many :orders, :through => :cronologies
end
釷下面的代碼讓我獲得分配給訂單的所有狀態。
@order.statuses
......但如何獲得按照cronology表的「created_at」屬性排序的狀態?