Skip to content

Commit cd70662

Browse files
committed
Associations. Don't raise error when load associated models with broken foreign key
1 parent a3de8b7 commit cd70662

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/dynamoid/associations/many_association.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def initialize(*args)
2525
# @private
2626
# @since 0.2.0
2727
def find_target
28-
Array(target_class.find(source_ids.to_a))
28+
return [] if source_ids.empty?
29+
30+
Array(target_class.find(source_ids.to_a, raise_error: false))
2931
end
3032

3133
# @private

lib/dynamoid/associations/single_association.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def disassociate(_hash_key = nil)
109109
def find_target
110110
return if source_ids.empty?
111111

112-
target_class.find(source_ids.first)
112+
target_class.find(source_ids.first, raise_error: false)
113113
end
114114

115115
def target=(object)

0 commit comments

Comments
 (0)