New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong SQL for handle :dependent => :nullify objects that have default_scope with ordering on many tables #8217
Comments
|
Hey, thanks for the great reproduction steps. These kinds of bugs make my head hurt, so I'm not sure what's right here, just wanted to let you know I've read it. |
|
Reading Active Record changes in Rails 4, I was wondering that default_scope -> { includes(:building).order("rooms.name ASC, buildings.name ASC").references(:building) }But no, it doesn't. This issue is present in rails 4 too (today's master). |
|
@Envek Can you confirm whether or not this problem persists in Rails 4? |
|
Yes, it persists. I've checked it on both |
|
Can you post a gist as per the section 1.2 of Rails guide http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#create-a-self-contained-gist-for-active-record-issues? I'll take a look. Thanks. |
|
@Envek if you change to then the problem goes away. Here is the gist I created to test this issue. https://gist.github.com/neerajdotname/5356529 The episode of railscasts has detailed info about |
|
@neerajdotname, I know, it fixes. But sadly My test case gist: https://gist.github.com/Envek/5360783 |
|
@Envek thanks for the gist. I'll take a look. |
|
Hey did you ever get a chance to take a look at this @neerajdotname? (Just triaging ;) |
|
@JonRowe I'll look into it this week. |
|
|
|
This issue has been automatically marked as stale because it has not been commented on for at least The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the Thank you for all your contributions. |
|
This issue has been automatically closed because of inactivity. If you can still reproduce this error on the Thank you for all your contributions. |
Description
If dependent model have
default_scopewith bothincludesandordermethods (with a string SQLORDER BYclause, that references to included model table), when deleting parent model (withhas_many :children, :dependent => :nullify), Rails tries to nullify dependent model foreign keys with SQL query, that respectsordermethod and doesn't respectsincludes(and/orjoins).Example (gives
missing FROM-clause entry for table "buildings"in PostgreSQL):Expected behaviour
Environment
Have tested on:
How to reproduce
Create rails app:
Assume that models are looks like this (note the default_scope):
In rails console create some buildings, rooms and departments:
And try to delete one department:
The text was updated successfully, but these errors were encountered: