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
添加到收藏夹?