Skip to content
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

Association building broken with upgrade to 0.7.0 #232

Closed
Timmitry opened this issue May 4, 2021 · 4 comments · Fixed by #277
Closed

Association building broken with upgrade to 0.7.0 #232

Timmitry opened this issue May 4, 2021 · 4 comments · Fixed by #277
Assignees
Labels

Comments

@Timmitry
Copy link

Timmitry commented May 4, 2021

When upgrading this gem from 0.6.3 to 0.7.0, I noticed a regression when building associations without saving them.

I think it was caused by this Changelog entry:

Handle with_deleted association option as a scope (#147, by Matijs van Zuijlen)

What fails is e.g. the following scenario:

Order = Class.new(ActiveRecord::Base) do
  has_many :order_items
end
OrderItem = Class.new(ActiveRecord::Base) do
  belongs_to :order, with_deleted: true
end

order_item = OrderItem.new
order = Order.new(order_items: [order_item])
order.order_items.first.order # Returns nil, but should return the order

The above example does return the order in 0.6.3, but not in 0.7.0. It does work when removing the with_deleted: true option from the association.

I will open a PR with a failing spec 🙂

@turnon
Copy link

turnon commented Oct 27, 2021

I can reproduce without acts_as_paranoid. It seems ActiveRecord's problem, not this gem. When you add scope on association, it just returns nil.

@skukx
Copy link

skukx commented Apr 4, 2022

I'm not sure I follow that logic. This bug only occurs after upgrading acts_as_paranoid. No rails upgrades or changes implemented. I'm experiencing the same issue with a project I'm currently working on. This bug is preventing us from being able to upgrade from 0.6.2 to 0.8.0. In the least, it may be good to list this issue as a breaking change

@mvz
Copy link
Contributor

mvz commented Apr 9, 2022

I've checked and the behavior in 0.6.2 with the :with_deleted option matched the default Rails behavior with non-paranoid models.

My preliminary understanding is that unscoped associations automatically set up the inverse relation, whereas scoped ones do not. That's why the change in #147 broke the old behavior: Use of :with_deleted now automatically makes it a scoped relation.

In a sense, @turnon is right: given the implementation of :with_deleted as a scoped association, the behavior is as expected based on how ActiveRecord works. However, users of ActsAsParanoid expect :with_deleted to behave like an unscoped association in this case, just as it did in version 0.6.2.

@mvz
Copy link
Contributor

mvz commented Apr 22, 2022

A fix for this has just been released in version 0.8.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants