#1081 ✓resolved
Brock Whitten

primary key and foreign keys do not match

Reported by Brock Whitten | October 7th, 2009 @ 02:21 PM | in 0.10.2

dm property "Serial" creates an integer with a length of 10 digits. but foreign keys are 11 digits long. Expected behaviour is that they are same length to get true foreign key relationship with mysql.

see attached file for example.

tested on:
dm-core 0.10.1
mysql 5.1.39
ruby 1.9.1p243 and 1.8.7p174(REE)

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 8th, 2009 @ 12:23 PM

    • Milestone set to 0.10.2
    • State changed from “new” to “resolved”
    • Assigned user set to “Dan Kubb (dkubb)”

    If you are explicitly defining your FKs in your child models, then they won't match up with the Serial type in the parent model, which now have their :min option set to 1. This means if you have auto-validation, it will prevent you from inserting 0 or a negative number in the field. In MySQL it will also set the database constraints so that the column uses an UNSIGNED integer, further preventing any invalid data from being persisted.

    Make sure you add the :min => 1 option to your FK properties, and this problem will be resolved.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 8th, 2009 @ 12:32 PM

    Another thing I should add is don't define your FKs explicitly unless you know what you are doing, and you are prepared to deal with cases like this. DM handles making sure the FKs match up properly, and there's a chance that an explicit declaration may not be correct in future iterations.

  • Brock Whitten

    Brock Whitten October 8th, 2009 @ 01:01 PM

    I think in the past you did not get access to the FK attribute unless it was explicitly declared. I have tested some edge cases such as adding :nullable => true to the belongs_to and everything seems to be working well. Sorry for taking up your time. I appreciate the explanation.

    If there is any documentation anywhere you would like me to touch up on this topic, let me know.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Attachments

Referenced by

Pages