#1390 ✓not-applicable
Alex

"has 1" association ignores :required => false

Reported by Alex | August 18th, 2010 @ 08:18 PM

has 1, :author, 'Person', 
       :child_key  => [:author_id],
       :required => false

This results in a foreign key property with :required => true. Not sure if this is by design, but seems that a has 1 should be an optional relationship. You can of course create the property yourself to declare it :required => false to get around this issue.

Comments and changes to this ticket

  • brian

    brian September 6th, 2010 @ 01:54 PM

    I'm also experiencing this issue.

    You can of course create the property yourself to declare it :required => false to get around this issue.

    @Alex: I'd like to be able to use the workaround mentioned above, can you elaborate on where the property should be created?

    I've this in my model:

    has 1, :client, :required => false
    

    but I'm still getting 'projects.client_id may not be NULL'

    Any ideas?

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) September 6th, 2010 @ 02:34 PM

    • State changed from “new” to “unconfirmed”

    Try declaring :required => false on the belongs_to on the "other side" of the relationship.

  • brian

    brian September 6th, 2010 @ 04:04 PM

    Thanks Dan, in the meantime I had done just that:

      belongs_to :client, :required => false
    
    That solved it for me anyway.
  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) October 31st, 2010 @ 10:29 AM

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

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 »

Pages