簡體   English   中英

Rails,ActiveModel模型關聯?

[英]Rails, ActiveModel Model Associations?

我有以下兩種模式:

User
Mentions (user_id, mentioned_by)

@take.user給了我創建者,但我需要提到的用戶。 我想做的是:@ mention.mentioner,它使用提到的by_by獲取user_id

如何在模型中設置該關系? 我試過了:

User.rb:
  has_many :mentions


Mention.rb
belongs_to :user
belongs_to :user, :as => "mentioner", :foreign_key => "mentioned_by"

但是那個錯誤。 想法? 謝謝

mention.rb ,試試這個:

belongs_to :user
belongs_to :mentioner, :class_name => "User", :foreign_key => "mentioned_by"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM