with multiple databases CKfAR chooses the default connection rather than the connection used to create the SQL

7 views
Skip to first unread message

tapestrydude

unread,
Feb 6, 2012, 2:14:48 AM2/6/12
to Composite Keys for ActiveRecord
Hi

I'm using both Postgres and Mysql databases.

My default development: connection is with Postgres.

The tables that have composite keys use the Mysql connection.

When I do something like:

c=Category.first;p=Product.first;c.products.push(p)

where Category and Product have a categories_products join table

I get a *Mysql* error that I've trace to the Quoting process for the
field names of the join table :

ActiveRecord::StatementInvalid: Mysql::Error: You have an error in
your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near
'"categories_products" ("category_id", "product_id") VALUES (1, 2)' at
line 1: INSERT INTO "categories_products" ("category_id",
"product_id") VALUES (1, 2)

When I change the development: connection to a Mysql database it
works.

So, in my initial Postgres dev: environment , I presume that
Composite Keys for ActiveRecord somehow ends up calling the quoting
mechanism from the *default* connection rather than the *called*
connection.

I'll have a look and see how that works, and it's probably not a huge
problem.

But got me very confused for a while.

Thanks

Daniel

cfis

unread,
Mar 16, 2012, 4:26:39 AM3/16/12
to Composite Keys for ActiveRecord
Hi Daniel,

Thanks for the report. Definitely submit a patch to the github
project page at:

https://github.com/drnic/composite_primary_keys

Charlie
Reply all
Reply to author
Forward
0 new messages