This project is archived and is in readonly mode.
:delete_all with named_scope fails when named_scope has :joins
-
spovich
Not sure if this is a limitation of ActiveRecord, but for PostgreSQL, the necessary SQL statement would need to specify the USING clause which is roughly equivalent to the FROM clause
http://www.postgresql.org/docs/8.4/static/sql-delete.html
So, it would need to generate the following:
DELETE from email_subscribers USING users WHERE users.type='OemUser'
For MySQL, it looks like you can specify a regular LEFT JOIN after the FROM clause.
-
Matt Jones
The special syntax for Postgres may be part of why this isn't supported; see also #2558 Support for :joins in ActiveRecord::Base#update_all for discussion on update_all, which had a similar issue.
-
spovich
Well, the general sentiment in #2558 Support for :joins in ActiveRecord::Base#update_all is that you should just write the SQL which is no problem, however, named scopes are so useful and clean, that it seems a shame not to be able to use them in this way.
Also, the documentation for #delete_all is very clear about the risks and limitations, so I don't see that as an issue.
-
Rohit Arondekar
- State changed from new to stale
- Importance changed from to
Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.
-
spovich
I no longer work at the company where I ran into this problem. Also, I'm not working on any rails 2.3.x apps (only Rails 3 now). I tested this with Rails 3 and postgresql and it works fine, so please close the issue.