按子属性排序,在多态多态关联中

时间:2012-03-13 13:27:06

标签: ruby-on-rails nested polymorphism polymorphic-associations

我有以下型号

class Airplane < ActiveRecord::Base
  has_many :airtags
  has_many :pictures, :through => :airtags
end

class Airtag < ActiveRecord::Base
  attr_accessible :airable_type, :airable_id, :airplane_id
  belongs_to :airplane
  belongs_to :airable, :polymorphic => true
end

class Picture < ActiveRecord::Base
  belongs_to :picturable, :polymorphic => true

  has_many :airtags, :as => :airable,   :dependent => :destroy
  has_many :airplanes, :through => :airtags
end

在我的飞机表演中,我想列出所有照片,按照他们的名字排序。

1 个答案:

答案 0 :(得分:0)

@airplane.pictures.order(:name)