Open fmichaut-diff opened 1 year ago
@fmichaut-diff try defining your association with { with_deleted }
scope like this:
class SalesReceipt < ApplicationRecord
belongs_to :order
has_many :order_items, -> { with_deleted }, through: :order
end
Depending on your needs sometimes it might make sense to define 2 associations :order_items
and :order_items_with_deleted
.
Currently, you can create a model with
with_deleted: true
if you want this model to still show deleted records, but only forbelongs_to
assotiations.The second exemple currently raises this error
In some cases, we might want to be able to use
with_deleted: true
for has_many relationships. Exemple:In this situation, if I delete an item from an order (let's say the customer did not want it anymore), I might still need the reference inside the sales receipt since the receipt was printed before the item was deleted, so it should still have access to it (because it depends on it).
Is it something that could be implemented ?