-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behaviour of non-persisted has_many through associations #9548
Comments
this looks strange indeed. I'll take a look and report back. |
I can confirm the problem. It's related to the join model that's built when you call def test_include?
ActiveRecord::Base.logger = Logger.new(STDOUT)
person = Person.new(first_name: "Peter")
post = Post.new(title: "Cats & Dogs", body: "are pets")
person.posts << post
# assert person.posts.include?(post)
person.posts.delete(post)
# assert_not person.posts.include?(post), "should not contain the post after deletion but did."
person.save!
# assert_not person.posts.include?(post)
end This leads to the following SQL statements:
The post was not inserted but the @carlosantoniodasilva @rafaelfranca what do you think? |
When target record is deleted then in-memory association record should be deleted for hm:t case. Fixes rails#9548.
This issue has been automatically marked as stale because it has not been commented on for at least The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the Thank you for all your contributions. |
I tried to reproduce this on |
Proposed patch still works. Should I send a new PR? |
Fixed by #29593. |
Consider a basic hm:t association
(
Link
andPage
are trivial).If you add and remove an item from
links
, it still thinks the item is magically present... in the empty collection:Tried this on both 3.2.12 and 4.0.0.beta1.
PS. If you save the records, it works as expected.
The text was updated successfully, but these errors were encountered: