Module: UniqueGenerator::UniqueChecks::AR
- Defined in:
- lib/unique_generator.rb
Instance Method Summary collapse
-
#unique_field?(field_name) ⇒ Boolean
Returns whether or not the given field is unique to every item.
Instance Method Details
#unique_field?(field_name) ⇒ Boolean
Returns whether or not the given field is unique to every item.
44 45 46 47 48 49 50 51 52 |
# File 'lib/unique_generator.rb', line 44 def unique_field?(field_name) scope = self.class.where(field_name => send(field_name)) # When we have an id, check for those with a different id. if id.present? conditions = self.class.scoped.table[:id].eq(id).not scope = scope.where(conditions) end scope.empty? end |