Permalink
Browse files

Minor changes to match the style of the rest of Sequel.

  • Loading branch information...
1 parent 8f56471 commit b9425b1235338900fd99db7e4b994e586572806f @chanks chanks committed May 29, 2012
Showing with 5 additions and 5 deletions.
  1. +5 −5 lib/sequel/plugins/nested_attributes.rb
@@ -164,8 +164,8 @@ def nested_attributes_create(reflection, attributes)
# Find an associated object with the matching pk. If a matching option
# is not found and the :strict option is not false, raise an Error.
def nested_attributes_find(reflection, pk)
- pk = pk.map {|k| k.to_s }
- unless obj = Array(send(reflection[:name])).find{|x| [*x.pk].map{|k| k.to_s} == pk}
+ pk = pk.map{|k| k.to_s}
+ unless obj = Array(send(reflection[:name])).find{|x| Array(x.pk).map{|k| k.to_s} == pk}
raise(Error, "no matching associated object with given primary key (association: #{reflection[:name]}, pk: #{pk})") unless reflection[:nested_attributes][:strict] == false
end
obj
@@ -223,10 +223,10 @@ def nested_attributes_setter(reflection, attributes)
return if (b = reflection[:nested_attributes][:reject_if]) && b.call(attributes)
modified!
klass = reflection.associated_class
- sym_keys = [*klass.primary_key]
- str_keys = sym_keys.map { |k| k.to_s }
+ sym_keys = Array(klass.primary_key)
+ str_keys = sym_keys.map{|k| k.to_s}
if ((pk = attributes.values_at(*sym_keys)).all? || (pk = attributes.values_at(*str_keys)).all?)
- attributes = attributes.dup.delete_if { |k,v| str_keys.include? k.to_s }
+ attributes = attributes.dup.delete_if{|k,v| str_keys.include? k.to_s}
if reflection[:nested_attributes][:destroy] && klass.db.send(:typecast_value_boolean, attributes.delete(:_delete) || attributes.delete('_delete'))
nested_attributes_remove(reflection, pk, :destroy=>true)
elsif reflection[:nested_attributes][:remove] && klass.db.send(:typecast_value_boolean, attributes.delete(:_remove) || attributes.delete('_remove'))

0 comments on commit b9425b1

Please sign in to comment.