2
我有这三种模式:轨道4 - 验证独特性的has_many通过
用户:
class User < ActiveRecord::Base
validates :name, presence: true
validates :surname, presence: true
validates :email, presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }
has_many :permissions, dependent: :destroy
has_many :stores, through: :permissions
end
商店:
class Store < ActiveRecord::Base
validates :name, presence: true
validates :description, presence: true
has_many :permissions
has_many :users, through: :permissions
end
权限:
class Permission < ActiveRecord::Base
belongs_to :user
belongs_to :store
end
哪有我验证了01的独特性基础上,store.id
?
你不验证电子邮件的独特性在用户模式?不应该将电子邮件作为用户的唯一标识符吗? – wesley6j
我需要允许用户使用同一封电子邮件订阅多个商店。 – user4523968
更有意义的是,用户可以订阅多个商店而无需注册多个账户? – wesley6j