I have been able to create a 1:M relationship using DataMapper and
update the child items as well after creation. However, I have been
unable to add to that collection.

Let's say I have

class Parent
  include DataMapper::Resource

  property :id, Serial
  ...

  has n, :children
end

class Child
  include DataMapper::Resource

  property :id, Serial
  ...
  belongs_to :parent
end

Whenever I try to add to the child collection belonging to a certain
parent instance, I get either DataMapper::UpdateConflictError or
"DataObjects::IntegrityError: ERROR:  duplicate key value violates
unique constraint "children_pkey" DETAIL:  Key (id)=(1) already
exists.

I have tried a whole host of approaches. The most promising seemed
parent.children.create(attributes), but that led to the
IntegrityError. What is the preferred approach for adding a new item
to the collection?

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