[英]How do I set up a :through ActiveRecord association in Ruby On Rails?
我在弄清楚關聯方面遇到困難。 我需要通過“交易”將用戶鏈接到“反饋”。 反饋具有transaction_id屬性,而Transaction具有Seller_id。 我該如何使用關聯? 到目前為止,這里是我所擁有的,感謝您的幫助! 謝謝!
class Feedback < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :feedbacks
end
class Transaction < ActiveRecord::Base
belongs_to :seller, :class_name => 'User', :foreign_key => 'seller_id'
end
用戶->交易->反饋
class User < ActiveRecord::Base
has_many :transactions
has_many :feedbacks, through: :transactions, foreign_key: 'seller_id'
end
class Transaction < ActiveRecord::Base
has_many :feedback
belongs_to :seller, class_name: 'User', foreign_key: 'seller_id'
end
class Feedback < ActiveRecord::Base
belongs_to :transaction
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.