lundi 23 octobre 2017

Remove records from has_many Rails association with a single query

I'm having trouble removing records from a has_many association in Rails without triggering unnecessary queries. Essentially, I have a model which has a has_many relation on it, and I want to remove multiple records from it based on some criteria. I want to be able to simultaneously keep the association up to date, but also remove the records from the database, and only require one DELETE query to do this. I've tried assigning to the relation with the new objects (which generates unnecessary UPDATE queries) and calling delete_all (which makes one query but doesn't update the association).

Aucun commentaire:

Enregistrer un commentaire