Hi,

I have an association, but there are validation errors, so I've setup
a before :valid? hook to correct them on the associated model.
Because of this I need to call #valid? and then #save on the model to
run the hook.  The result is that both resources are created, but they
are not associated.

There seems to be an issue that when #valid? is called, the
association#set does not take place in
#assign_nested_attributes_for_related_resource

If I remove the name :required restriction on the Place resource and
dont call the #valid? method, everything seems to work fine.  I've
spent hours trying to wrap my head around this.  Hopefully someone can
shed some light.

Here are the classes:
<code>
class Person
  include DataMapper::Resource
  property :name, String

  belongs_to :place, :required => false
  accepts_nested_attributes_for :place

  before :valid?, :set_place_name

  def set_place_name
    self.place_attributes = {'name' => self.name}.merge!
(@place_attributes)
  end
end

class Place
  include DataMapper::Resource
  property :name, String, :required => true, :length => 128
end
</code>

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to