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.

Bad table name when using join and hash condition

#3071

Here is an example from Rails Guides

time_range = (Time.now.midnight - 1.day)..Time.now.midnight

Client.all :joins => :orders, :conditions => {:orders => {:created_at => time_range}}

If the orders table is using non standard table name, set with set_table_name, then above creates wrong condition. ":joins => :orders" works fine. However the hash condition always produces "orders" for the table name. I guess the hash condition doesn't take correct table name, the name which is set via set_table_name.

Reported by Greg Dan · August 19th, 2009 @ 10:38 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from activerecord to activerecord, bugmash

    September 25th, 2009 @ 12:50 PM

  2. Ken Richard
    Ken Richard

    verified

    Build small app with two models and tested the join. Renamed one of the model classes and added def self.table_name. The problem only occurs when the condition is added.

    September 26th, 2009 @ 04:16 PM

  3. Anuj Dutta
    Anuj Dutta

    This is similar to bug #3027 where set_table_name is quietly ignored.

    September 27th, 2009 @ 12:04 AM

  4. Ken Richard
    Ken Richard

    I have attached a patch. The problem was inside active record base.rb. The function calls itself and passes connection.quote_table_name(attr.to_s). In this case the attr was the name of the class. The class has an override for set_table_name. The class name was quoted instead of the table name. The patch gets the real table name from the class if the attr is a symbol (see :orders in the original example).

    September 27th, 2009 @ 12:05 AM

  5. Anuj Dutta
    Anuj Dutta

    Patch applied successfully. Green on tests.

    September 27th, 2009 @ 12:15 AM

  6. Ken Richard
    Ken Richard

    Attached is a test case for the patch. Fails without the above update. Passes after the above patch is applied.

    September 27th, 2009 @ 01:39 AM

  7. Anuj Dutta
    Anuj Dutta

    Verified. Behaves as stated.

    September 27th, 2009 @ 01:47 AM

  8. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from activerecord, bugmash to activerecord, bugmash, bugmash-review

    September 27th, 2009 @ 11:52 AM

  9. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from activerecord, bugmash, bugmash-review to activerecord, bugmash-review

    September 27th, 2009 @ 12:33 PM

  10. Rizwan Reza
    Rizwan Reza
    • Tag changed from activerecord, bugmash-review to activerecord, bugmash

    May 15th, 2010 @ 06:45 PM

  11. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:38 PM

  12. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:38 PM