File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -1041,9 +1041,17 @@ def strict_loaded_associations
1041
1041
1042
1042
def _find_record ( options )
1043
1043
if options && options [ :lock ]
1044
- self . class . preload ( strict_loaded_associations ) . lock ( options [ :lock ] ) . find ( id )
1044
+ self . class . preload ( strict_loaded_associations ) . lock ( options [ :lock ] ) . find_by! ( _in_memory_query_constraints_hash )
1045
1045
else
1046
- self . class . preload ( strict_loaded_associations ) . find ( id )
1046
+ self . class . preload ( strict_loaded_associations ) . find_by! ( _in_memory_query_constraints_hash )
1047
+ end
1048
+ end
1049
+
1050
+ def _in_memory_query_constraints_hash
1051
+ return { @primary_key => id } unless self . class . query_constraints_list
1052
+
1053
+ self . class . query_constraints_list . index_with do |column_name |
1054
+ attribute ( column_name )
1047
1055
end
1048
1056
end
1049
1057
Original file line number Diff line number Diff line change @@ -1357,6 +1357,13 @@ def test_save_uses_query_constraints_config
1357
1357
assert_match ( /WHERE .*color/ , sql )
1358
1358
end
1359
1359
1360
+ def test_reload_uses_query_constraints_config
1361
+ clothing_item = clothing_items ( :green_t_shirt )
1362
+ sql = capture_sql { clothing_item . reload } . first
1363
+ assert_match ( /WHERE .*clothing_type/ , sql )
1364
+ assert_match ( /WHERE .*color/ , sql )
1365
+ end
1366
+
1360
1367
def test_destroy_uses_query_constraints_config
1361
1368
clothing_item = clothing_items ( :green_t_shirt )
1362
1369
sql = capture_sql { clothing_item . destroy } . first
You can’t perform that action at this time.
0 commit comments