This project is archived and is in readonly mode.

#1081 ✓committed
Hongli Lai

AssociationCollection starts transactions in the incorrect database

Reported by Hongli Lai | September 20th, 2008 @ 09:15 PM | in 2.x

Some AssociationProxy methods, e.g. #clear, start transactions. However, they start the transaction in the wrong place. For example, suppose Author has_many :books. One would expect "author.books.clear" to start a transaction by calling Book.transaction, but the current implementation calls Author.transaction. Only has_and_belongs_to_many seems to get it right.

This patch fixes this bug, and also includes a unit test. All code in AssociationProxy subclasses now start transactions by calling AssociationProxy#transaction, which in turn calls .transaction on the association class. The reason why I added this method instead of calling @reflection.klass.transaction (as has_and_belongs_to_many does) is because I need the AssocationProxy#transaction hook for a database sharding plugin that I'm developing: the transaction needs to be activated in the correct shard, and this requires some additional housekeeping code.

The patch applies on 2-1-stable and on master.

Comments and changes to this ticket

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages