mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
upto 3.10
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
class Membership < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :beerclub
|
||||
end
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user