Files
openfoodnetwork/app/models/enterprise_role.rb
Matt-Yorkley 26ed44412f Update #validates definitions
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...`
2021-03-24 15:43:09 +00:00

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