#949 ✓not-applicable
ojak

"has 0..n" creates id columns that are not nullable in MySQL (even though 0 records should result in null value)

Reported by ojak | July 5th, 2009 @ 08:45 PM | in 0.10.0

"has 0..n" creates id columns that are not nullable in MySQL. If you have zero records, then the key id should be NULL. This means that "has 0..n" will always fail validations.

Comments and changes to this ticket

  • ojak

    ojak July 5th, 2009 @ 09:11 PM

    == WORKAROUND == It can work correctly, but a belongs_to on the related model MUST be explicitly set to :nullable=>true for the "has 0..1" work properly.

    Is this the intended behavior or should a has 0..n automatically imply that the belongs_to is nullable?

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) July 6th, 2009 @ 02:42 AM

    • State changed from “new” to “not-applicable”

    This is intended behavior.

    When you say has 0..n, what it means is "There should be 0 or more resources at the other end (the target)". By itself 0..n doesn't say anything about the target being required to link backwards.

    While it is true that FK will be created so it is required (i.e. not nullable), it's totally valid to have a has 0..n being paired with a belongs_to :nullable => true.

  • ojak

    ojak July 7th, 2009 @ 04:14 PM

    "it's totally valid to have a has 0..n being paired with a belongs_to :nullable => true."

    I agree with that, however, what I was saying is that a "has 0..n" will not work unless "belongs to :model, :nullable=>false" is set on the receiving end (since validations will fail on the '0' case).

  • ojak

    ojak July 7th, 2009 @ 04:16 PM

    sorry... typo... damn lighthouse.

    "it's totally valid to have a has 0..n being paired with a belongs_to :nullable => true."

    I agree with that, however, what I was saying is that a "has 0..n" will not work unless "belongs to :model, :nullable=>true" is set on the receiving end (since validations will fail on the '0' case if :nullable is set to false, which is the default behavior).

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

Pages