I have a Ruby on Rails application in which I have licenses, elements that can be licensed, and a table that lists two (what elements in which quantity are present in the license?). Similar to the items in the basket.
Some of the items will no longer be sold, but I intend to store them in the database. Then I created soft-delete and used the default scope for the template and for relations. But when I try to modify existing entries using the appropriate template, I get an exception:ActiveRecord :: ReadOnlyRecord
My templates look like this:
class Item <ActiveRecord :: Base
default_scope {where (deleted: false)}
end
class LicenseItem <ActiveRecord :: Base
belongs_to: license, touch: true
belongs_to: item
end
class License <ActiveRecord :: Base
has_many: license_items,
-> {joins (: item) .where (items: {deleted: false})},
dependent:: destroy
end
In this way:
pry (main)> License.find (0) .license_items [0] .readonly?
=> true
Is there a way to make this ratio not just reading?
I have already tried adding readonly (false)
at the end of the field has_many
to License
without success.