This project is archived and is in readonly mode.
establish_connection does not support joins
-
scott
+1 currently on a project where we have to monkey patch column_alias to get this to work correctly. Why it's aliasing off the current connection and not the reflected one seems to be a bug. Patch below
module ActiveRecord::Associations::ClassMethods def column_aliases(join_dependency) join_dependency.joins.collect{|join| join.column_names_with_alias.collect{|column_name, aliased_name| if join.respond_to?(:reflection) "#{join.reflection.klass.connection.quote_table_name join.aliased_table_name}.#{connection.quote_column_name column_name} AS #{aliased_name}" else "#{connection.quote_table_name join.aliased_table_name}.#{connection.quote_column_name column_name} AS #{aliased_name}" end }}.flatten.join(", ") end end -
scott
Sorry forgot to mention had to fix quote_table_name (for Mysql) to include the db name automatically, we originally hoped that would take care of it all.
class ActiveRecord::ConnectionAdapters::MysqlAdapter def database @connection_options[3] end def quote_table_name(name) if name.index(".").nil? name = database + "." + name end @quoted_table_names[name] ||= quote_column_name(name).gsub('.', '`.`') end end -
scott
Yea it's been a fun week, you are probably gonna need this to fix the table names as well
class ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation def table_alias_for(table_name, table_alias) "#{reflection.klass.connection.quote_table_name(table_name)} #{table_alias if table_name != table_alias}".strip end end -
jonbro (at gmail)
I am also having problems with this, and cannot find my way around active record enough to figure it out. The issue that I am having is if it is being used for an order, the join still fails.
-
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
-
Mike Dalessio
Please note that I've opened a github issue for this: https://github.com/rails/rails/issues/539