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