Comments on “Learning CakePHP: Foreign Key Constraint Violation” http://robwilkerson.org/2009/01/30/learning-cakephp-foreign-key-constraint-violation/feed 2010-02-24T09:04:36-04:00 Chyrp Learning CakePHP: Foreign Key Constraint Violation tag:robwilkerson.org,2010-02-24:/id/167//comment_17245 2010-02-24T09:04:36-04:00 2010-02-24T09:04:36-04:00 Rob Wilkerson http://robwilkerson.org <p>Readability. <code>locations</code> is really just a lookup table. Whenever possible, I like to be able to open a table that uses lookup data and have it be meaningful without requiring the extra step of writing <span class="caps">SQL</span> to join the lookup. In this case, opening the <code>events</code> table would show a location like <code>MAINTENT</code>. Just by looking at the event record, I can tell where it’s happening.</p> <p>You’re right that Cake may be smart enough if it was an <code>int</code>, but I use <span class="caps">UUID</span>s. That’s just a <code>char</code> datatype so it may not behave any differently. It’s a good point to test, though. I may try it.</p> Learning CakePHP: Foreign Key Constraint Violation tag:robwilkerson.org,2010-02-24:/id/167//comment_17235 2010-02-24T06:11:56-04:00 2010-02-24T06:11:56-04:00 Dieter_be http://www.kangaroot.net <p>Why do you use the varchar datatype?<br /> I don’t allow users to enter “no relation” so I’m not sure, but if you use a proper datatype for id’s and foreign keys (like unsigned int), Cake might be smart and use null instead of an empty string for unset FK’s.<br /> If it doesn’t do that, I suggest to file a bug report.</p>