Wednesday, June 30, 2010

Re: Undefined id and don´t know why....

Have you done this:
http://book.cakephp.org/view/437/primaryKey
in your Model?


Erik Starck


On Wed, Jun 30, 2010 at 11:49 AM, Davor Ilic <webfacer@gmail.com> wrote:
> Hi cakers,
>
> i have a problem by using this code:
>
> if(!empty($this->data)) {
>
> $product = $this->Product->save($this->data);
>
>
> if(!empty($product)) {
>
>
> $this->loadModel('Kattaxonomie');
>
>
> $counted_katId = count($this->data['Kat']);
>
>
> for($i=0;$i<$counted_katId;$i++) {
>
>
> $this->Kattaxonomie->set(array(
>
>
> 'product_id' => $this->Product->id,
>
>
> 'kat_id' => $this->data['Kat']['kat_id'][$i]
>
>
> ));
>
> $this->Kattaxonomie->save();
>
> }
>
> $this->redirect(array('action'=>'list_products'));
>
>
> }
>
> }
>
> i got always undefined id why i set my primery_key to product_id and not
> only id.
>
> And this is the ouput from cakePHP:
>
> Notice (8): Undefined index: id [CORE/cake/libs/model/model.php, line 1325]
>
> Code | Context
>
> $this = AppModel
> AppModel::$useDbConfig = "default"
> AppModel::$useTable = "kattaxonomies"
> AppModel::$displayField = false
> AppModel::$id = false
> AppModel::$data = array
> AppModel::$table = "kattaxonomies"
> AppModel::$primaryKey = "id"
> AppModel::$_schema = array
> AppModel::$validate = array
> AppModel::$validationErrors = array
> AppModel::$tablePrefix = "wf_"
> AppModel::$name = "Kattaxonomie"
> AppModel::$alias = "Kattaxonomie"
> AppModel::$tableToModel = array
> AppModel::$logTransactions = false
> AppModel::$cacheQueries = false
> AppModel::$belongsTo = array
> AppModel::$hasOne = array
> AppModel::$hasMany = array
> AppModel::$hasAndBelongsToMany = array
> AppModel::$actsAs = NULL
> AppModel::$Behaviors = BehaviorCollection object
> AppModel::$whitelist = array
> AppModel::$cacheSources = true
> AppModel::$findQueryType = NULL
> AppModel::$recursive = 1
> AppModel::$order = NULL
> AppModel::$virtualFields = array
> AppModel::$__associationKeys = array
> AppModel::$__associations = array
> AppModel::$__backAssociation = array
> AppModel::$__insertID = NULL
> AppModel::$__numRows = NULL
> AppModel::$__affectedRows = NULL
> AppModel::$_findMethods = array
> $data = null
> $validate = true
> $fieldList = array()
> $defaults = array(
> "validate" => true,
> "fieldList" => array(),
> "callbacks" => true
> )
> $_whitelist = array()
> $fields = array(
> "product_id",
> "kat_id"
> )
> $options = array(
> "validate" => true,
> "fieldList" => array(),
> "callbacks" => true
> )
> $field = "modified"
> $keyPresentAndEmpty = false
> $exists = false
> $dateFields = array(
> "modified",
> "updated",
> "created"
> )
> $db = DboMysql
> DboMysql::$description = "MySQL DBO Driver"
> DboMysql::$_baseConfig = array
> DboMysql::$startQuote = "`"
> DboMysql::$endQuote = "`"
> DboMysql::$_useAlias = true
> DboMysql::$_commands = array
> DboMysql::$fieldParameters = array
> DboMysql::$tableParameters = array
> DboMysql::$columns = array
> DboMysql::$index = array
> DboMysql::$alias = "AS "
> DboMysql::$methodCache = array
> DboMysql::$cacheMethods = true
> DboMysql::$__bypass = true
> DboMysql::$__sqlOps = array
> DboMysql::$virtualFieldSeparator = "__"
> DboMysql::$connected = true
> DboMysql::$fullDebug = true
> DboMysql::$error = NULL
> DboMysql::$affected = 3
> DboMysql::$numRows = 3
> DboMysql::$took = 1
> DboMysql::$_result = resource
> DboMysql::$_queriesCnt = 9
> DboMysql::$_queriesTime = 4
> DboMysql::$_queriesLog = array
> DboMysql::$_queriesLogMax = 200
> DboMysql::$_queryCache = array
> DboMysql::$__descriptions = array
> DboMysql::$_sources = array
> DboMysql::$connection = resource
> DboMysql::$config = array
> DboMysql::$configKeyName = "default"
> DboMysql::$_transactionStarted = false
> DboMysql::$cacheSources = true
> DboMysql::$results = resource
> DboMysql::$map = array
> DboMysql::$__booleans = array
> $updateCol = "created"
> $result = true
> $values = array(
> "18",
> "1"
> )
> $v = array(
> "product_id" => "18",
> "kat_id" => "1"
> )
> $n = "Kattaxonomie"
> $y = "1"
> $x = "kat_id"
> $count = 2
> $success = true
> $created = false
> $cache = array()
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> 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
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: