You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed an unexpected behavior in a context of has_one ... through associations.
Imagine a model:
class Alice < ApplicationRecord
has_one :bob
has_one :charlie, through: :bob
end
and then
record = Alice.preload_associations_lazily.find(some_id)
assert record.lazy_preload_context.present?, "lazy context is missing for alice"
# at this point record has no associations loaded
record.charlie
# at this point record has both bob and charlie associations loaded
assert record.charlie.lazy_preload_context.present?, "lazy context is missing for charlie"
assert record.bob.lazy_preload_context.present?, "lazy context is missing for bob"
Observed behavior: the last assertion fails Expected behavior: all assertions succeed
docker compose up -d && bin/setup && bin/rails test
Output:
% bin/rails test
Running 1 tests in a single process (parallelization threshold is 50)
Run options: --seed 56792
# Running:
F
Failure:
AliceTest#test_the_truth [test/models/alice_test.rb:15]:
lazy context is missing for bob
rails test test/models/alice_test.rb:4
Finished in 0.127767s, 7.8267 runs/s, 46.9605 assertions/s.
1 runs, 6 assertions, 1 failures, 0 errors, 0 skips
The text was updated successfully, but these errors were encountered:
Hello Dmitry 👋
I noticed an unexpected behavior in a context of
has_one ... through
associations.Imagine a model:
and then
Observed behavior: the last assertion fails
Expected behavior: all assertions succeed
Steps to reproduce:
docker compose up -d && bin/setup && bin/rails test
Output:
The text was updated successfully, but these errors were encountered: