我有以下内容:
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是NULLself.project.publication.id设置正确
数据库也反映了这一点:projects.publication_id列是NULL.