This project is archived and is in readonly mode.
Bad table name when using join and hash condition
Reported by Greg Dan | August 19th, 2009 @ 10:38 AM
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.
Comments and changes to this ticket
-
CancelProfileIsBroken September 25th, 2009 @ 12:50 PM
- Tag changed from activerecord to activerecord, bugmash
-
Ken Richard September 26th, 2009 @ 04:16 PM
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.
-
Anuj Dutta September 27th, 2009 @ 12:04 AM
This is similar to bug #3027 where set_table_name is quietly ignored.
-
Ken Richard September 27th, 2009 @ 12:05 AM
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).
-
Ken Richard September 27th, 2009 @ 01:39 AM
Attached is a test case for the patch. Fails without the above update. Passes after the above patch is applied.
-
CancelProfileIsBroken September 27th, 2009 @ 11:52 AM
- Tag changed from activerecord, bugmash to activerecord, bugmash, bugmash-review
-
CancelProfileIsBroken September 27th, 2009 @ 12:33 PM
- Tag changed from activerecord, bugmash, bugmash-review to activerecord, bugmash-review
-
Rizwan Reza May 15th, 2010 @ 06:45 PM
- Tag changed from activerecord, bugmash-review to activerecord, bugmash
-
Santiago Pastorino February 2nd, 2011 @ 04:38 PM
- 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.
-
Santiago Pastorino February 2nd, 2011 @ 04:38 PM
- State changed from open to stale
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>