This project is archived and is in readonly mode.
Condition Hashes through Joins Gives Fails when Circular References are Used
Reported by Ben Woodcroft | July 26th, 2008 @ 05:40 AM | in 2.x
On Rails edge github http://github.com/rails/rails/co...
Say I’m trying to get the names of all the books on a particular shelf (which are book1 and book2), and all I have is the name of one of the books (book1).
Using your method, I would
Book.all(
:joins => {:bookshelf => :books},
:conditions => {:bookshelves => {:books => {:title => 'book1'}}}
).collect{|b| b.title}
I end up getting
=> ["book1", "book1"]
instead of
Attached skeleton rails app I tested the bug on, including sqlite with included data.
=> ["book1", "book2"]
Comments and changes to this ticket
-
Ben Woodcroft July 26th, 2008 @ 05:46 AM
Sorry, to clarify, the github link is to the one where the feature was introduced, not the one to where the attached rails app was updated. That is 26 July 2008 or thereabouts
http://github.com/rails/rails/co...
Thanks,
ben
-
Pratik July 26th, 2008 @ 03:10 PM
- State changed from new to invalid
You should look at the query generated by Book.all(:joins => {:bookshelf => :books}) and use whatever the alias AR uses for books table.
:conditions => {:books_alias_or_table_name => {:title => 'book1'}}
-
Ben Woodcroft July 28th, 2008 @ 01:39 AM
But not having to look/remember/change it when rails does was the coolest thing about your patch..
Looks like I've confused myself slightly - I thought you had to specify the whole path to the table from the original via the joins.
It would be nice if the conditions and joins were somehow merged into one hash - that way there would be no confusion about the table the conditions were specified on.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>