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.

Check for primary key in habtm when the association is defined

#3128

In this commit:

http://github.com/rails/rails/commit/9d51f6286680b832b0df5e3ce28857...

We started to check if the primary key in habtm was defined and raise an error if it does. However, the current implementation checks for it every time we insert a record for the first time, per association and then per request.

The patch attached changes it, so it's checked only when the association is defined. I was planning to move the logic to Reflection.check_validity!, but this method is invoked every time an association proxy is created. I tried to make check_validity! to be invoked just on load as well, but :through validity can only be ensured in runtime (when all records are supposed to be loaded).

Patch is for master and 2-3-stable.

Reported by José Valim · September 1st, 2009 @ 12:22 PM

State: resolved
Milestone: none
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. Repository
    Repository
    • State changed from new to committed

    (from [da636809daca9c338200811d3590e446f57c8e81]) Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted.

    [#3128 Check for primary key in habtm when the association is defined state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/da636809daca9c338200811d3590e4...

    September 1st, 2009 @ 06:20 PM

  2. Repository
    Repository

    (from [594a281d663dd8a7801651f4aea7e5b7f4f02548]) Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted.

    [#3128 Check for primary key in habtm when the association is defined state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/594a281d663dd8a7801651f4aea7e5...

    September 1st, 2009 @ 06:20 PM

  3. José Valim
    José Valim
    • State changed from committed to incomplete

    Make tests fail on Postgres.

    September 2nd, 2009 @ 10:09 PM

  4. Repository
    Repository
    • State changed from incomplete to open

    (from [3b6a9a020e7e6f71ab6f9ffcf1ef59c57437ca69]) Revert "Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted."

    Test failures on PostgreSQL.

    [#3128 Check for primary key in habtm when the association is defined state:open]

    This reverts commit da636809daca9c338200811d3590e446f57c8e81.
    http://github.com/rails/rails/commit/3b6a9a020e7e6f71ab6f9ffcf1ef59...

    September 2nd, 2009 @ 10:45 PM

  5. Repository
    Repository

    (from [2b82708b0efb3a3458e8177beab58f0c585788ae]) Revert "Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted."

    Test failures on PostgreSQL.

    [#3128 Check for primary key in habtm when the association is defined]

    This reverts commit 594a281d663dd8a7801651f4aea7e5b7f4f02548.
    http://github.com/rails/rails/commit/2b82708b0efb3a3458e8177beab58f...

    September 2nd, 2009 @ 10:46 PM

  6. Jeremy Kemper
  7. sds
    sds

    Here is a patch to fix the issue in this code I reported in ticket #3190 HABTM no longer works when using multiple databases

    • the issue being that has_primary_key? uses the ActiveRecord::Base's connection, which fails when using multiple databases (should use @owner.connection).

    September 12th, 2009 @ 08:42 AM

  8. Repository
  9. Repository
  10. Repository
    Repository
    • State changed from open to resolved

    (from [78790e47b8603917e2f2352f973a2de7769cb74b]) Revert "Revert "Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted.""

    This reverts commit 2b82708b0efb3a3458e8177beab58f0c585788ae.

    [#3128 Check for primary key in habtm when the association is defined state:resolved]

    Conflicts:

    activerecord/lib/active_record/associations.rb
    activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
    

    http://github.com/rails/rails/commit/78790e47b8603917e2f2352f973a2d...

    November 23rd, 2009 @ 06:42 PM