mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
Where the presence of an object is being validated and that object comes from an *association*, we should use `validates :object, presence: true` instead of `validates :object_id, presence: true`. This does not apply in the same way to validations on uniqueness of certain attributes, such as `validates :object_id, uniqueness...`
10 lines
361 B
Ruby
10 lines
361 B
Ruby
class EnterpriseRole < ActiveRecord::Base
|
|
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
|