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
has_one association works stand-alone but does not, when used in scope #22407
Comments
This looks a bit like another issue I've been trying to understand: #9157 It seems like there are some chicken and egg problems with regard to setting up associations in time for assignments lambdas, callbacks, and also the association lambdas like in this ticket. |
@timbreitkreutz so do you think this issue has a chance to be examined by someone from Rails team or is it rather a rare case which is not worth it? |
Can you create a standard reproduction script that uses one of the templates here? |
Sorry @andreydeineko I got absorbed in another project so I haven't any chance to do more research... |
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. |
Each of defined associations work 100%. The one we are interested in is
has_one :last_discretionary_note
.Generated SQL:
Which returns the expected result - last discretionary_note.
What I initially need:
sort exposition_targets by the last discretionary_note.attribute
To do the sorting I want to create a scope:
Now the problem:
Company::ExpositionTarget.joins(:last_discretionary_note)
returns nothing.Generated SQL:
This query is wrong and does not take into account the definition of
has_one: last_discretionary_note
.QUESTION:
Why does AR not treating the
has_one
association correctly in scope? And, what is more important - where is my mistake and how do I achieve what I need?Again, schematically I need the following:
The text was updated successfully, but these errors were encountered: