我繼承其具有代碼:ror - 包含has_many和belongs_to兩端的外鍵?
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
這也是如此......我只是想回答他的問題哈哈。 – Batkins