upto 3.10

This commit is contained in:
Aaro Koivukangas
2023-08-10 20:02:11 +03:00
parent babe5573b1
commit cb57e9643c
40 changed files with 634 additions and 1 deletions
+16
View File
@@ -0,0 +1,16 @@
class Beerclub < ApplicationRecord
has_many :memberships, dependent: :destroy
has_many :users, through: :membership
validates :name, presence: true
validates :founded, numericality: { greater_than_or_equal_to: 1040,
only_integer: true }
validate :creation_year_not_in_future
def creation_year_not_in_future
if founded > Time.now.year
errors.add :founded, "cannot be in the future"
end
end
end
+4
View File
@@ -0,0 +1,4 @@
class Membership < ApplicationRecord
belongs_to :user
belongs_to :beerclub
end
+2
View File
@@ -5,4 +5,6 @@ class User < ApplicationRecord
has_many :ratings
has_many :beers, through: :ratings
has_many :memberships, dependent: :destroy
has_many :beer_clubs, through: :memberships
end