2013-08-29 38 views
0

在我的Rails 4应用程序,我的开发模式有一个用户,如:营造了一个多态关联

class Developer < ActiveRecord::Base 
    has_one :user, as: :account 
    ... 
end 

而在我的用户模型我有

class User < ActiveRecord::Base 
    belongs_to :account, polymorphic: true 
end 

当开发者记录创建我想要自动创建与开发人员关联的用户。这可能吗?或者有没有办法遵循轨道指南?

+0

是的,你可以在控制器或回调(例如创建后)中执行此操作。你尝试过吗? – simonmorley

+0

我会在Developer模型中这样做,使用'self.create_user'之类的after_creae回调函数。但实际上并不明显,为什么只要使用一对多关联,就需要首先使用多态关联。 – Almaron

回答