【发布时间】:2012-01-24 20:44:10
【问题描述】:
我继承的代码有:
class Graphic < ActiveRecord::Base
has_many :comments, :foreign_key => 'asset_id',
:conditions => 'asset_type_id = 5',
:order => 'created_at', :dependent => :destroy
class Comment < ActiveRecord::Base
belongs_to :graphic, :foreign_key => :asset_id
在我看来 has_many 不应该有foreign_key(我相信它在belongs_to 中被引用)但我不确定,你知道吗?
即应该是
class Graphic < ActiveRecord::Base
has_many :comments,
:conditions => 'asset_type_id = 5',
:order => 'created_at', :dependent => :destroy
class Comment < ActiveRecord::Base
belongs_to :graphic, :foreign_key => :asset_id
【问题讨论】:
标签: ruby-on-rails ruby activerecord has-many belongs-to