Module: CompositePrimaryKeys::ActiveRecord::Relation::InstanceMethods
- Defined in:
- lib/composite_primary_keys/relation.rb
Instance Method Summary collapse
Instance Method Details
#delete(id_or_array) ⇒ Object
21 22 23 24 25 |
# File 'lib/composite_primary_keys/relation.rb', line 21 def delete(id_or_array) # CPK # where(@klass.primary_key => id_or_array).delete_all where(ids_predicate(id_or_array)).delete_all end |
#destroy(id) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/composite_primary_keys/relation.rb', line 27 def destroy(id) # CPK #if id.is_a?(Array) # id.map { |one_id| destroy(one_id) } #else find(id).destroy #end end |
#ids_predicate(id) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/composite_primary_keys/relation.rb', line 5 def ids_predicate(id) predicate = nil if id.kind_of?(CompositePrimaryKeys::CompositeKeys) id = [id] end id.each do |composite_id| self.primary_keys.zip(composite_id).each do |key, value| eq = table[key].eq(value) predicate = predicate ? predicate.and(eq) : eq end end predicate end |