Show
added a comment - This is quite a complex project so I'll try as best as I can.
What is happening here is that I'm adding another category (id:28) to the object (in this case an entry) that allready has one existing category (id: 10). The primary Id's are named - id!
The Code
public function setJsonData($query,$data){
$_query=$ this ->primaryQuery($query,self::RELATIONS_FULL); //generates DQL query - not relevant
$_record=$_query->getOne(array(),2); //Fetches the existing record from DQL query
$data=$ this ->fromJsonData($data,$query); //Cleans up the recieved JSON data and returns an array
ss_error::log($data,'In data'); //Data output 1 - incoming data
ss_error::log($_record->toArray(),'Existing data'); //Data output 2 - record contents
$_record->synchronizeWithArray($data, true ); //Synchronize
ss_error::log($_record->toArray(),'Merged data'); //Data output 3 - resulting datac
$_record->save(); //#ERROR#
return $_record->toArray( true );
}
Data output 1 - incoming, cleaned up data
array (
'id' => '5',
'active' => true ,
'timedpub' => true ,
'slug' => 'how_we_work',
'date_pub' => NULL,
'date_rej' => NULL,
'UserCreate' => NULL,
'UserModify' => NULL,
'Category' =>
array (
0 => '10',
1 => '28',
),
'User' =>
array (
),
'Translation' =>
array (
'en' =>
array (
'headline' => 'How we work',
'name' => 'how we work',
'teaser' => NULL,
'text' => '...',
'lang' => 'en',
'id' => '5',
),
'sv' =>
array (
'headline' => 'Så arbetar vi',
'name' => 'Så arbetar vi',
'teaser' => '<br />',
'text' => '...',
'lang' => 'sv',
'id' => '5',
),
),
'user_create_id' => NULL,
'user_modify_id' => NULL,
)
Data output 2 - record contents
array (
'id' => '5',
'active' => true ,
'timedpub' => true ,
'slug' => 'how_we_work',
'date_pub' => NULL,
'date_rej' => NULL,
'user_create_id' => NULL,
'user_modify_id' => NULL,
'created_at' => '2009-11-12 01:41:36',
'updated_at' => '2009-11-12 01:41:36',
'Category' =>
array (
0 =>
array (
'id' => '10',
'slug' => 'arbetsmetod',
'path' => '/om_hamilton/arbetsmetod',
'parent_id' => NULL,
'owner_id' => '8',
' public ' => true ,
'created_at' => '2009-11-12 01:41:38',
'updated_at' => '2009-11-12 01:41:38',
'Translation' =>
array (
'sv' =>
array (
'id' => '10',
'name' => 'arbetsmetod',
'headline' => 'Vår arbetsmetod',
'lang' => 'sv',
),
),
),
),
'User' =>
array (
),
'Translation' =>
array (
'en' =>
array (
'id' => '5',
'headline' => 'How we work',
'name' => 'how we work',
'teaser' => NULL,
'text' => '...',
'lang' => 'en',
),
'sv' =>
array (
'id' => '5',
'headline' => 'Så arbetar vi',
'name' => 'Så arbetar vi',
'teaser' => '<br />',
'text' => '...',
'lang' => 'sv',
),
),
)
Data output 3 - result after Synchronize
array (
'id' => '5',
'active' => true ,
'timedpub' => true ,
'slug' => 'how_we_work',
'date_pub' => NULL,
'date_rej' => NULL,
'user_create_id' => NULL,
'user_modify_id' => NULL,
'created_at' => '2009-11-12 01:41:36',
'updated_at' => '2009-11-12 01:41:36',
'Category' =>
array (
0 =>
array (
'id' => '10',
'slug' => 'arbetsmetod',
'path' => '/om_hamilton/arbetsmetod',
'parent_id' => NULL,
'owner_id' => '8',
' public ' => true ,
'created_at' => '2009-11-12 01:41:38',
'updated_at' => '2009-11-12 01:41:38',
'Translation' =>
array (
'sv' =>
array (
'id' => '10',
'name' => 'arbetsmetod',
'headline' => 'Vår arbetsmetod',
'lang' => 'sv',
),
),
),
1 =>
array (
'id' => '28',
'slug' => 'att_arbeta_hos_oss',
'path' => '/karriar/arbeta_hos_oss',
'parent_id' => NULL,
'owner_id' => '21',
' public ' => true ,
'created_at' => '2009-11-12 01:41:39',
'updated_at' => '2009-11-12 01:41:39',
),
),
'User' =>
array (
),
'Translation' =>
array (
'en' =>
array (
'id' => '5',
'headline' => 'How we work',
'name' => 'how we work',
'teaser' => NULL,
'text' => '...',
'lang' => 'en',
),
'sv' =>
array (
'id' => '5',
'headline' => 'Så arbetar vi',
'name' => 'Så arbetar vi',
'teaser' => '<br />',
'text' => '...',
'lang' => 'sv',
),
),
)
The error
'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5-10' for key 'PRIMARY''
Added 1.2.0-BETA2