delete_all with joins gives error missing from clause #7287

Closed
chrismhilton opened this Issue Aug 8, 2012 · 3 comments

Comments

Projects
None yet
3 participants

I'm using Rails 3.2.7 and PostgreSQL 9.1.4 with pg gem 0.14.0. When chaining delete_all with the joins method the generated SQL does not include the joins table resulting in an error.

User.joins(:posts).where(:posts => {:title => 'delete'}).delete_all

ActiveRecord::StatementInvalid: PG::Error: ERROR:  missing FROM-clause entry for table "posts"
LINE 1: DELETE FROM "users" WHERE "posts"."title" = 'delete'

I can see that there's a previous issue #5649 for the same problem so I have created a striped down application to ensure that my issue isn't a result of any other gems I'm using but I still get the same result.

Member

steveklabnik commented Aug 11, 2012

@chrismhilton the fix was applied to master, and you're only using 3.2.7. That's why you haven't seen the fix.

Contributor

benmoss commented Aug 11, 2012

If you check out the code in 1c8e222, and then check it against what's in your ActiveRecord gem, you can see it hasn't been included yet. Just guessing here, but it probably won't make it in until 4.0. You can backport a patch if you want: http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#backporting

Member

steveklabnik commented Aug 11, 2012

@benmoss you can also see if a commit is in a branch by running $ git branch --contains <hash>. That's what I did:

$ git branch --contains 6f6c290                                                               ✘
  close_discovered_pg_connection
  escape_html_test
  extract_observers
  fix-2394
  fix-5738
  fix_2301
  fix_5680
  master
  remove_composed_of

Note that 3-2-stable isn't in there.

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