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”属性排序的状态?