This project is archived and is in readonly mode.

#3128 ✓resolved
José Valim

Check for primary key in habtm when the association is defined

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

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.

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

Tags