Don't access the $data property directly; use the set() method: $this->MemberSearchCriteria->set('member_id', $user_id); $this->MemberSearchCriteria->save(...);
Or use the $id property: $this->MemberSearchCriteria->id = $user_id; // Doesn't matter what the PK is called, always use `id` here $this->MemberSearchCriteria->save(...); Remember: whatever the actual name of the primary key column, the property name is ALWAYS `id`. (note: calling set() in the 1st example will detect that 'member_id' is the primary key and internally set the `id` property, so both methods are equivalent.) On Jun 9, 1:11 pm, "Raitis L." <[EMAIL PROTECTED]> wrote: > Hi, > > I have a question about save() function. It doesn't trigger Update > (instead it does Insert) when I want to update data. > > When I tried to do the save(), i got a following message: > > ------------------------------ > Query: INSERT INTO `2p_member_search_criterias` > (`gender`,`reason`,`age_from`,`age_to`,`height_from`,`height_to`,`weight_from`,`weight_to`,`photo`,`member_id`) > VALUES (1,'0',20,21,127,127,60,70,0,73) > > Warning (512): SQL Error: 1062: Duplicate entry '73' for key 1 > ------------------------------ > > What could be a reason for that? > > There is an existing record with member_id = 73. And I just want to > update some of its fields. > > Here is a data saving code: > > $data['MemberSearchCriteria']['member_id'] = $user_id; > $this->MemberSearchCriteria->save($data['MemberSearchCriteria']); > > I have also specified which is a primary key in table for the > "MemberSearchCriteria" model: > > var $primaryKey = 'member_id'; > > In addition, similar code works for other models and databases, except > for this one. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---