Skip to content
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

Joining an association with scope block failing #11963

Closed
iwiznia opened this issue Aug 21, 2013 · 5 comments · Fixed by #12011
Closed

Joining an association with scope block failing #11963

iwiznia opened this issue Aug 21, 2013 · 5 comments · Fixed by #12011

Comments

@iwiznia
Copy link
Contributor

iwiznia commented Aug 21, 2013

When defining a scope block for associations fails in some cases.
The problem isn't when getting the association but when joining by it, and it depends on how the association scope is defined.
I included 4 test cases. 2 of them work, and 2 of them fail.
In the cases that fail, the conditions aren't joined with an AND but with a comma.

Here's the gist with the tests:
https://gist.github.com/iwiznia/6295952

@robin850
Copy link
Member

I can confirm that it fails with 4.0.0, 4-0-stable and master.

@pftg
Copy link
Contributor

pftg commented Aug 21, 2013

Indeed - weird! Confirmed for master and db: sqlite3, pg. Investigating...

@iwiznia
Copy link
Contributor Author

iwiznia commented Aug 21, 2013

Oh, I forgot. Yes 4.0 stable and master. I also tested with mysql and fails too.
I guess that what's happening is that in some place it falling to array#to_s instead of doing array#join(' AND ') or something like that.
The thing is that I have no idea where to look to find the code that generates that. ActiveRecord is an untamable beast for me... :-)

pftg added a commit to jetthoughts/rails that referenced this issue Sep 6, 2013
In order to remove duplication with joining arel where constraints with
`AND`, all constraints on `build_arel` are collapsed into one head node: `Arel::Nodes::And`

Closes: rails#11963
pftg added a commit to jetthoughts/rails that referenced this issue Sep 13, 2013
In order to remove duplication with joining arel where constraints with
`AND`, all constraints on `build_arel` are collapsed into one head node: `Arel::Nodes::And`

Closes: rails#11963
@rafaelfranca
Copy link
Member

Closed by #12011

@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 16, 2013

So collapse_wheres, that was the place to fix it. I looked and couldn't figure out where the bug was happening...Thanks!!

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

Successfully merging a pull request may close this issue.

4 participants