9
I have a Ruby on Rails application in which I have licenses, items that can be licensed, and a table that lists the two (Which items do you have in the license?). Analogously to items in a shopping cart.
Some of the items will no longer be marketed, but I intend to keep them in the database. I then created a soft-delete and I used a standard scope for the model and for the relationships. But when I try to change existing records using the related model, I get an exception: ActiveRecord::ReadOnlyRecord
My models are 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 any way to make this relationship not just read?
I’ve tried to add readonly(false)
at the end of the has_many
in License
unsuccessful.
What version of Rails are you using?
– Duke
Was using 4.0.0, update to 4.0.2 solved!
– Vargas