Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Condition Hashes through Joins Gives Fails when Circular References are Used

#710

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"]

Reported by Ben Woodcroft · July 26th, 2008 @ 05:40 AM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Ben Woodcroft
    Ben Woodcroft

    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

    July 26th, 2008 @ 05:46 AM

  2. Pratik
    Pratik
    • 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'}}

    July 26th, 2008 @ 03:10 PM

  3. Ben Woodcroft
    Ben Woodcroft

    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.

    July 28th, 2008 @ 01:39 AM