tags:

views:

17

answers:

1

Hi,

I have an Account and a User Model with a one to one relationship, I'm trying to use saveAll to save the data to the db:

$this->Account->set(array(  'uid' => uniqid(),'date_registration' => date('Y-m-d'),'state' =>  1));
if ($this->Account->saveAll($this->data) ) {

However, saveAll seems to be saving only the data in $this-date and ignores the previous set statement, unlike save. Is that the case, any workarounds?

Thanks.

+2  A: 

What is the problem to make the code this way:

$this->data['Acount']['uid'] = uniqid();
$this->data['Acount']['date_registration'] = date('Y-m-d');
$this->data['Acount']['state'] = 1;
if ($this->Account->saveAll($this->data) ) {
   ...
}

A better approach is to do this in beforeSave() in the model :) But so far this should work as well.

Nik
I started to add my own answer using array_merge, but I would do it your way anyway - it's more readable. +1
Leo