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
When I access @subscription.subscription_addons everything is great and it returns only SubscriptionAddons where deleted_at is null.
But when I need to access @subscription.addons, the response also includes Products joined through already deleted SubscriptionAddons. In other words with_deleted that I apply to belongs_to :product/:price also applies to has_many :subscription_addons even thought it wasn't explicitly declared there. Basically, it unscopes where(::deleted_at) where it shouldn't.
The text was updated successfully, but these errors were encountered:
heaven
changed the title
with_deleted unscopes everything when joining multiple associations
with_deleted unscopes everything when joining through multiple associations
Jun 8, 2022
@kroehre nope and I don't think there is an easy fix, unfortunately. In my case, I simply stopped using acts_as_paranoid on SubscriptionAddon, which is just a :through model between Subscription and Price. This allowed me to work without with_deleted in associations. Also, building propper foreign key constraints and validations prevents deletions of a Price with active Subscriptions so this works somehow. Not as planned, though.
We have Subscriptions, Products, Prices, and AddOns.
When I access
@subscription.subscription_addons
everything is great and it returns onlySubscriptionAddons
where deleted_at is null.But when I need to access
@subscription.addons
, the response also includesProducts
joined through already deletedSubscriptionAddons
. In other wordswith_deleted
that I apply tobelongs_to :product/:price
also applies tohas_many :subscription_addons
even thought it wasn't explicitly declared there. Basically, it unscopeswhere(::deleted_at)
where it shouldn't.The text was updated successfully, but these errors were encountered: