Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

AssociationCollection starts transactions in the incorrect database

#1081

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.

Reported by Hongli Lai · September 20th, 2008 @ 09:15 PM

State: committed
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Hongli Lai
    Hongli Lai
    • Title changed from AssociationProxy starts transactions in the incorrect database to AssociationCollection starts transactions in the incorrect database

    Here's an updated patch. AssociationProxy#transaction has been moved to AssociationCollection because it makes no sense for non-collection associations. More tests have been added.

    The following patch is for edge.

    September 20th, 2008 @ 09:56 PM

  2. Hongli Lai
  3. Repository
    Repository
    • State changed from new to committed

    (from [70b8ea4fa6f432919340345ae0d5af6aa8f87ec8]) Make AssociationCollection start transactions in the correct database.

    AssociationCollection now starts transactions by calling AssociationCollection#transaction instead of @owner.transaction or @reflection.klass.transaction.

    Signed-off-by: Michael Koziarski michael@koziarski.com

    [#1081 AssociationCollection starts transactions in the incorrect database state:committed] http://github.com/rails/rails/co...

    September 23rd, 2008 @ 07:32 PM