Permalink
Browse files

Added patch to HasManyAssociation foreign_key_present? method to work…

… with array of keys
  • Loading branch information...
1 parent 1770d7f commit fcc2f7286c028a4f80c85516372a1edef5d2a672 tbeauvais committed Jan 6, 2013
Showing with 14 additions and 0 deletions.
  1. +6 −0 lib/composite_primary_keys/associations/has_many_association.rb
  2. +8 −0 test/test_associations.rb
@@ -37,6 +37,12 @@ def delete_records(records, method)
end
end
end
+
+ def foreign_key_present?
+ # CPK
+ # owner.attribute_present?(reflection.association_primary_key)
+ reflection.association_primary_key.all?{ |key| owner.attribute_present?(key) }
+ end
end
end
end
@@ -269,4 +269,12 @@ def test_limitable_reflections
assert_equal(1, memberships.length)
assert_equal([1,1], memberships[0].id)
end
+
+ def test_foreign_key_present_with_null_association_ids
+ group = Group.new
+ group.memberships.build
+ associations = group.association_cache[:memberships]
+ assert_equal(false, associations.send('foreign_key_present?'))
+ end
+
end

0 comments on commit fcc2f72

Please sign in to comment.