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
My team and I noticed that has_one associations are remaining cached after any calls to destroy the associated model. has_many calls are behaving as expected.
For example, a User 'has_many :addresses and has_one :main_address in our schema (MainAddress is a subclass of Address).
Here is an RSpec to help reproduce precisely.
RSpec.describe User, type: :model do
let(:user) { create(:user) }
let(:address) { create(:address, user_id: user.id, type: "MainAddress")}
it 'an address should not return if it has been soft-deleted' do
user.addresses << address
expect(user.main_address.user_id).to eq(user.id)
user.main_address.really_destroy! # or user.main_address.destroy!
expect(user.addresses.count).to eq(0) # this expectation passes on the has_many
expect(user.main_address).to be_nil # this expectation fails and still returns a MainAddress (with deleted_at filled in)
end
end
We have to call reload on the parent model to get it to work. (i.e., user.reload) Then user.main_address return nil as expected.
The text was updated successfully, but these errors were encountered:
My team and I noticed that
has_one
associations are remaining cached after any calls to destroy the associated model.has_many
calls are behaving as expected.For example, a User
'has_many :addresses
andhas_one :main_address
in our schema (MainAddress
is a subclass ofAddress
).Here is an RSpec to help reproduce precisely.
We have to call reload on the parent model to get it to work. (i.e.,
user.reload
) Thenuser.main_address
return nil as expected.The text was updated successfully, but these errors were encountered: