1
我有雙重多態關聯,基本上我打算把Bond模型和VideoInterview模型關聯起來。他們以這種方式取得:雙重多態關聯
債券遷移
class CreateBonds < ActiveRecord::Migration
def change
create_table :bonds do |t|
t.references :sourceable, :polymorphic => true
t.references :targetable, :polymorphic => true
t.string :operation
t.string :score
t.timestamps
end
end
end
bond.rb
class Bond < ActiveRecord::Base
belongs_to :sourceable, :polymorphic => true
belongs_to :targetable, :polymorphic => true
end
question.rb
class Question < ActiveRecord::Base
has_many :bonds, :as => :sourceable
has_many :bonds, :as => :targetable
end
video_interview.rb
class VideoInterview < ActiveRecord::Base
has_many :bonds, :as => :sourceable
has_many :bonds, :as => :targetable
end
我應該如何修改訂單,用戶該協會正確的模式? 如果我打電話@ question.bonds,我認爲有一些問題,因爲sourceable和targettable是在同一個has_many:bonds下定義的。 我想ti make @ question.sources,並將所有與問題有關的債券作爲可源元素。 謝謝