我有看起来像的多态关联
class Certificate < ActiveRecord::Base
attr_accessible :certification_id, :certified_id, :certified_type
belongs_to :certification
belongs_to :certified, :polymorphic => true
end
class Certification < ActiveRecord::Base
attr_accessible :name, :slug
belongs_to :association
end
class Association < ActiveRecord::Base
has_many :certifications
attr_readonly :name, :id
attr_protected :name
end
假设User
模型
class User < ActiveRecord::Base
has_many :certificates, :as => :certified
end
我正在尝试association
从多态关联中访问对象
u = User.first
u.certificates
返回的实例数组Certificate
u.certificates.first.certification
返回实例Certification
但
u.certificates.first.certification.association
返回stack level too deep
错误并在第二次运行时控制台/服务器崩溃illegal hardware instruction
显示消息
我确实意识到这个表达式很难成为代码美的女王,但它应该有效,不是吗?