#1351 confirmed
Jonathan Stott (namelessjon)

has 1 doesn't respect :defaults for existing resources

Reported by Jonathan Stott (namelessjon) | July 4th, 2010 @ 09:27 AM

If you have a Model (which has a number of existing resources) that you add a new has 1 relationship to, defaults for that relationship will not be respected.

class Parent
  include DataMapper::Resource
  property :id, Serial

  has 1, :child, :default => proc { Child.new }
end

class Child
  include DataMapper::Resource
  belongs_to :parent, :key => true
end

If the models are as shown, then:

@existing_parent = Parent.first
@existing_parent.child
#=> nil

@new_parent      = Parent.new
@new_parent.child
#=> #<Child ...>

See the attached ticket for a script to demonstrate the problem.

Comments and changes to this ticket

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 »

Attachments

Pages