File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
spec/integration/associations Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ def evolve(object)
60
60
if object_id_field? || object . is_a? ( Document )
61
61
if association . polymorphic?
62
62
association . convert_to_foreign_key ( object )
63
+ elsif object . is_a? ( Document ) && object . respond_to? ( association . primary_key )
64
+ primary_key_field . evolve ( object . send ( association . primary_key ) )
63
65
else
64
66
object . __evolve_object_id__
65
67
end
@@ -142,6 +144,11 @@ def related_id_field
142
144
@related_id_field ||= association . klass . fields [ "_id" ]
143
145
end
144
146
147
+ def primary_key_field
148
+ @primary_key_field ||= association . klass . fields [ association . primary_key ]
149
+ end
150
+
151
+
145
152
# This is used when default values need to be serialized. Most of the
146
153
# time just return the object.
147
154
#
Original file line number Diff line number Diff line change 27
27
expect ( email . company . id ) . to eq ( company . id )
28
28
end
29
29
30
+ it "has the correct criteria" do
31
+ company = ForeignKeySpec ::Company . create! ( c : "3" )
32
+ email = ForeignKeySpec ::Email . create! ( company : company )
33
+
34
+ criteria = ForeignKeySpec ::Email . where ( company : company )
35
+
36
+ expect ( criteria . selector ) . to eq ( { "c_ref" => "3" } )
37
+ end
38
+
30
39
context 'with default scope' do
31
40
context 'using default scope' do
32
41
it 'looks up child' do
You can’t perform that action at this time.
0 commit comments