upto 3.11: added option to join to beerclub

This commit is contained in:
Aaro Koivukangas
2023-08-10 21:07:37 +03:00
parent cb57e9643c
commit 9ff0b5acc5
3 changed files with 13 additions and 2 deletions
+8
View File
@@ -1,4 +1,12 @@
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