Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support for MySQL DELETE USING #145

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

Enables delete_all on has_many :through associations, e.g.

chapter_one.paragraphs.where(:editor_id => 1).delete_all

DELETE FROM paragraphs USING paragraphs INNER JOIN sections ON paragraphs.section_id = sections.id WHERE sections.chapter_id = 1 AND paragraphs.editor_id = 1

The current behavior is to omit the join such that the following error is raised:

ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'sections.chapter_id' in 'where clause': DELETE FROM paragraphs WHERE sections.chapter_id = 1 AND paragraphs.editor_id = 1

This could also be implemented for postgresql visitor, although the non-standard USING clause would only contain the names of join tables and the join condition would be merged into the WHERE clause.

@teleological teleological Support for MySQL DELETE USING
* Enables delete_all on has_many :through associations, etc.
2d16af1

tamird commented Sep 16, 2014

@teleological looks like the current behaviour in rails 4.1 is to delete via a subquery that gets the IDs. In that case, the intermediate table entries are not deleted.

Looks like a bug in rails, but not one that is fixed by this PR (anymore?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment