我有3種型號的Rails如何創建一個多對多的關係,也節省誰創造了它
- 用戶
- 公司
- 標籤
我想創建一個多到User
和Tags
之間的很多關係,但我也想知道哪個Company
創建了這種關係,以便當用戶在數據庫中通過標籤搜索到用戶時系統僅在公司分配的標籤中進行搜索。
我知道如何創建的has_many關係
User
has_many: tags, through: :user_tags
has_many: user_tags
Tag
has_many: users, through: :user_tags
has_many: user_tags
UserTag
belongs_to: user
belongs_to: tag
但我不明白的是如何儲存誰創造了這個關係,再後來拉由特定公司所標記的所有用途。
我真的很感謝這方面的幫助。
感謝看看,我想一些弄明白這些:)這看起來像的東西,將工作 – Saadia