所以排序 - 具有以下設置:最好的方法,通過一個多態關聯
class Event < ActiveRecord::Base
has_many :invitations
end
class Invitation < ActiveRecord::Base
belongs_to :guest, :polymorphic => true
belongs_to :event
end
class Member > ActiveRecord::Base
has_many :invitations, :as => :guest
def full_name
[first_name, last_name].join(" ")
end
end
class Visitor > ActiveRecord::Base
has_many :invitations, :as => :guest
def full_name
name
end
end
最後,我希望能夠獲取由客人訂購了活動邀請FULL_NAME。我無法弄清楚 - 誰能幫我解決這個問題?將不勝感激:)
我想你只能使用Ruby這樣做不是因爲多態結構 – fl00r 2011-03-26 21:02:22
的SQL我猜你是對的!任何建議如何? – 2011-03-26 21:04:04