This project is archived and is in readonly mode.

#6291 ✓stale
Matthew O'Brien

HABTM inserts and deletes fail when models use non-default database

Reported by Matthew O'Brien | January 15th, 2011 @ 05:19 PM

HasAndBelongsToManyAssociation calls for the join table passing only the table name, which causes the default (ActiveRecord::Base) database to be used. This causes problems when two models with a habtm association use a different database than the default.

In released versions, this causes inserts and deletes to be attempted on the wrong database. I discovered this issue in 3.0.0, and I can see from the code that 3.0.3 would have the same problem. Recent changes in master look like they would change the symptoms of the problem, but the problem remains.

A workaround to this is to use :insert_sql and :delete_sql; when these are set, the correct connection is used.

Comments and changes to this ticket

  • rails

    rails April 19th, 2011 @ 01:00 AM

    • State changed from “new” to “open”

    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.

  • rails

    rails April 19th, 2011 @ 01:00 AM

    • 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=""></a>

People watching this ticket