[katello-devel] Beware of :id => false in our migrations unless HABTM
Ohad Levy
ohadlevy at redhat.com
Wed Dec 21 06:41:54 UTC 2011
----- Original Message -----
| Hi all,
| Today I've hit and interesting bug in Rails that showed up in our
| project [1].
Is that really a bug? if the many to many relationship is not HABTM
but via a model, then you need a separate ID for it,.. i.e. when
migrating from HABTM to has_may :though, you need to add an ID
column.
Ohad
| How to reproduce (katello-0.1.150-1):
| 1. create a table without primary id (:id => false in our migration)
| (system_tasks in our case)
| 2. create a model for that table (SystemTask)
| 3. use has_many to that model (in System has_many system_tasks)
| 4. create a record in SystemTask
| 5. try to destroy the assigned record (System)
| 6. enjoy NoMethodError: undefined method `eq' for nil:NilClass and
| really long stack trace.
| How to avoid:
| Besides previous hint not to use HABTM there is another rule of
| thumb:
| Don't use :id => false in migrations
| [1] -
| http://stackoverflow.com/questions/5085258/cant-destroy-record-in-many-to-many-relationship
| -- Ivan
| _______________________________________________
| katello-devel mailing list
| katello-devel at redhat.com
| https://www.redhat.com/mailman/listinfo/katello-devel
More information about the katello-devel
mailing list