mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
13 lines
284 B
Ruby
13 lines
284 B
Ruby
class Membership < ApplicationRecord
|
|
belongs_to :user
|
|
belongs_to :beerclub
|
|
|
|
validate :user_not_in_club
|
|
|
|
def user_not_in_club
|
|
if not Membership.find_by(user_id:user_id, beerclub_id:beerclub_id).nil?
|
|
errors.add :user_id, "is already in the beerclub"
|
|
end
|
|
end
|
|
end
|