mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Rails 5 introduced this new class to confine application-specific monkey patches to our models only, and not leak into other libraries using ActiveRecord::Base. https://bigbinary.com/blog/application-record-in-rails-5
10 lines
360 B
Ruby
10 lines
360 B
Ruby
class EnterpriseRole < ApplicationRecord
|
|
belongs_to :user, class_name: Spree.user_class.to_s
|
|
belongs_to :enterprise
|
|
|
|
validates :user, :enterprise, presence: true
|
|
validates :enterprise_id, uniqueness: { scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error) }
|
|
|
|
scope :by_user_email, -> { joins(:user).order('spree_users.email ASC') }
|
|
end
|