Hi Team,
I have a problem with $model->update when using columnMap on models. Exceptions/Validation seems not working during update of data, but I have no problem with $model->save/create. I tried to update a non-existent column/property, even wrong fields but $model->update() is returning TRUE which should be false since these fields are not on the model.
Here is my model:
class Account extends Model {
public $id;
public $firstName;
public $lastName;
public $email;
public function columnMap()
{
return [
'id' => 'id',
'first_name' => 'firstName',
'last_name' => 'lastName',
'email' => 'email',
];
}
}
On My controller:
//this is working
$account = new Account();
$account->firstName = $firstName; //post data
$account->lastName = $lastName; //post data
$account->email = $email; //post data
var_dump($account->create()); //save - return TRUE
var_dump($account->getMessages());
//this is working with error messages because first_name is not firstName (map)
$account = new Account();
$account->first_name = $firstName; //post data
$account->last_name = $lastName; //post data
$account->email = $email; //post data
var_dump($account->create()); //save - return FALSE
var_dump($account->getMessages());
However I expect the same behaviour on model update but not working..
//this is working because colums are correct
$account = Account::findFirst(2);
$account->firstName = $firstName; //post data
$account->lastName = $lastName; //post data
$account->email = $email; //post data
var_dump($account->update()); //update/save - return TRUE OK HERE
var_dump($account->getMessages());
//this is not working because colums are not correct but it RETURNS TRUE
$account = Account::findFirst(2);
$account->first_name = $firstName; //invalid col
$account->last_name = $lastName; //invalid col
$account->email_error = $email; //email_error is not valid
var_dump($account->update()); //update/save - return TRUE but no update on the database
var_dump($account->getMessages());
I found a related query here but its PHQL - PHQL seems working here
https://forum.phalcon.io/discussion/4355/phql-and-columnmap https://github.com/phalcon/cphalcon/issues/10344 https://github.com/dreamsxin/cphalcon/commit/91520ad9869fcacb28bf44e2ded686287e91f2bf
Help!
Thanks,