Hello.
I have started playing with ROM in a simple Rails project, gradually reimplementing functionality to study ROM. I have faced few issues that’s not relevant to this topic, I might open other tickets for them later.
The thing I haven’t found a good solution for is the ActiveRecord’s dependent: destroy
(or delete_all
, or nullify
). If I were using raw Sequel with Sequel models, there’s a plugin that does exactly this: Sequel::Plugins::AssociationDependencies. And, obviously, it’s built into AR.
So I wonder what are the best practices to achieve similar behavior in ROM? For now I’m manually removing dependent records via their relation, but such code should definitely be hidden somehow (a custom Command?)
Here’s the quick controller action:
def destroy
id = Integer(params[:id])
ROM.env.relations[:line_items].where(invoice_id: id).delete
repo.delete(id)
redirect_to invoices_url(filter: 'new'), flash: { notice: "Инвойс удалён" }
end
Thanks.