EDIT
I have modified my table so that my primary key is id, and everything works correctly. Still trying to figure this issue out.
I have the model below that I am using to handle various eav values. The issue that I am seeing is that when I use $Model->save(), it will always try to insert and not update. Even if I set the property/value of the primaryKey.
Event when inserting, I have noticed that I get this query the query below in my logs. The primary key of the table is value_id.
SELECT COUNT(*) AS `count` FROM `user_entity_varchars` AS `UserEntityVarchar`
WHERE `UserEntityVarchar`.`id` = '1'
When I output the debug of the model’s structure, this is what I am seeing:
[useDbConfig] => default
[useTable] => user_entity_varchars
[displayField] =>
[id] =>
[data] => Array
(
)
[table] => user_entity_varchars
[primaryKey] => id
For some reason it is not recognizing that the primary key is set in the model class.
This is the model that I am using:
<?php
class UserEntityVarchar extends UserAgentAppModel {
var $name = 'UserEntityVarchar';
var $primaryKey = 'value_id';
var $belongsTo = array(
'UserEntity'=>array(
'foreignKey' => 'entity_id'
));
var $hasOne = array(
'EavAttribute' => array(
'foreignKey' => 'attribute_id'
));
}
?>
You are setting the primaryKey on the model as “value_id”, try changing this line to:
Hope it helps!
cheers
pd, it is my first post!