0
的屬性值的關聯,我有三個型號:軌,驗證的has_many通過與孩子
class User < ApplicationRecord
has_many :game_accounts
has_many :favorite_game_accounts, through: :game_account_favorites, source: :game_account
end
class GameAccount < ApplicationRecord
belongs_to :user
has_many :favorite_users, through: :game_account_favorites, source: :user
end
class GameAccountFavorite < ApplicationRecord
belongs_to :user
belongs_to :game_account
validates_presence_of :user, :game_account
validates_uniqueness_of :user, scope: :game_account_id
end
這意味着User
可以擁有自己的GameAccounts
等Users
可以將它們添加到收藏夾。
我已添加scope
以防止一個用戶擁有相同的多個收藏夾GameAccount
。但是,有一個問題。用戶可以添加到收藏夾他自己的GameAccount。如何防止用戶將他自己的GameAccount
添加到收藏夾?