我有以下内容:
class Publication < ActiveRecord::Base
belongs_to :project, :inverse_of => :publication
before_create :bind_project
private
def bind_project
self.create_project
end
end
class Project < ActiveRecord::Base
has_one :publication, :inverse_of => :project
end
据此,在创建新模型Publication
时,模型上的publication_id
属性project
应由create_project
方法设置。
为什么它没有发生?
这就是我看到的bind_project
:
self.project_id
设置正确self.project.publication_id
是NULL
self.project.publication.id
设置正确
数据库也反映了这一点:projects.publication_id
列是NULL
.