jan javinto
2013-Mar-13 21:23 UTC
Dynamically changing table_name leaves sql_joins with cached names
Hi
I''m using dynamic tables in a Rails 3.2.12 application.
Consider 2 models that are associated: Order and OrderLine where Order has
many order_lines.
Now we set the table names for them:
Order.table_name=''v1_orders''
OrderLine.table_name=''v1_order_lines''
Query:
OrderLine.joins(:order).where(Order.table_name=>{:customer_id=>1}).all
Result: Select v1_order_lines.* FROM v1_order_lines INNER JOIN v1_orders ON
v1_orders.id=v1_order_lines.order_id WHERE v1_orders.customer_id=1
So far so good
Now we alter the table names:
Order.table_name=''v2_orders''
OrderLine.table_name=''v2_order_lines''
and requery:
Query:
OrderLine.joins(:order).where(Order.table_name=>{:customer_id=>1}).all
Result: Select v2_order_lines.* FROM v2_order_lines *INNER JOIN v1_orders
ON v1_orders.id*=v2_order_lines.order_id WHERE v2_orders.customer_id=1
Notice the INNER JOIN, it still uses the v1_ prefixes!!
I tried Model.uncached and
ActiveRecord::Base.connection.schema_cache.clear! but without luck.
Is this a bug? Or is there a way to easily get rid of this problem?
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.