This project is archived and is in readonly mode.
Association Table Names Incorrectly Generated when set_table_name used
-
CancelProfileIsBroken
- Tag set to bugmash
-
Elad Meidar
+1 verified
if
join_tableis missing from the macro options, the join table name will be calculated onassociations.rb#1596, by usingundecorated_table_name(http://apidock.com/rails/ActiveRecord/Base/undecorated_table_name/c....
This has obviously no reference to the actual table name, if set byset_table_name.I tried to patch that line to:
reflection.options[:join_table] ||= join_table_name(self.table_name, reflection.class_name.constantize.table_name)but
reflection.class_nameis out of scope in this context, if anyone has any idea how to access/load the association AR::Base class, that would be the key to access the current table name. -
Robert Rouse
+1 verified.
-
Robert Rouse
Here is what I've found so far.
Changing the line at 1596 in associations.rb (as Elad said) to the following does make it appear to work:
reflection.options[:join_table] ||= join_table_name(undecorated_table_name(self.table_name), undecorated_table_name(reflection.class_name.constantize.table_name))
I've tried it in a sample Rails app and it returns the right table name no matter which side of the association I use set_table_name on.
However, this causes the tests in AR to fail with uninitialized constant Project in the belongs_to_association_test.rb file.
I'm guessing this is what Elad meant before and it working for me is just a funny coincidence.
I'm still not sure what's up there.
-
Anuj Dutta
Project is the name of one of the models insides the activerecord/test/models directory where has_and_belongs_to_many has been defined and which is used for running the tests. The error basically means that your change has broken something.
-
Robert Rouse
andhapp:
I know what the model is. I'm not sure why it's broken something.
-
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.
-
Santiago Pastorino
- State changed from open to stale