Cannot update nested forms - Duplicate Key

15 views
Skip to first unread message

Paul

unread,
May 31, 2013, 1:52:57 PM5/31/13
to datam...@googlegroups.com
Hi,

Here is my problem.  I have a model that has a 1-1 association implemented using dm-accepts-nested-attributes:

class Message

  attribute_accessible :filter_attributes

  has 1, :message_filter, :constraint => :destroy

  has 1, :filter, :through => :message_filter, :via => :filter

  accepts_nested_attributes_for :filter

end

class Filter

   property :format, String

end

When I try to update a message:

message.update(params[:message])

I get the error message:

 PRIMARY KEY must be unique (code: 19, sql state: , query: INSERT INTO "filters" (....))

Why is it trying to do an insert instead of doing an update?

Paul

Paul

unread,
May 31, 2013, 4:27:28 PM5/31/13
to datam...@googlegroups.com
I set the id of the Filter object to nil and everything gets updated now.  Is this normal and should it work like this?
Reply all
Reply to author
Forward
0 new messages