【发布时间】:2011-03-26 20:59:46
【问题描述】:
所以 - 具有以下设置:
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
最后,我希望能够获取按客人全名排序的活动邀请。我不知道如何 - 谁能帮我解决这个问题?将不胜感激:)
【问题讨论】:
-
我认为你只能用 Ruby 而不是 sql 因为多态结构可以做到这一点
-
我猜你是对的!有什么建议吗?
标签: ruby-on-rails sorting polymorphic-associations nested-attributes