Hi
Having a few issues with the ORM executing unnessary queries which I can't find a way to disable. I'd much rather explicitly call save on models than have the ORM try do it's magic with certian relations.
Here is an example I have created in its simplest form, not actually tested this code, it's more to explain my problem.
Models:
// User
class User extends Model
{
public $userId;
public $countryId;
public $email;
public $createdAt;
public $updatedAt;
public function initialize()
{
$this->setSource('users');
$this->useDynamicUpdate(true);
$this->hasOne('countryId', 'Country', 'countryId', [
'alias' => 'country'
]);
}
public function beforeValidationOnCreate()
{
$this->createdAt = date('Y-m-d H:i:s');
}
public function beforeValidationOnUpdate()
{
$this->updatedAt = date('Y-m-d H:i:s');
}
}
// Country
class Country extends Model
{
public $countryId;
public $name;
public $createdAt;
public $updatedAt;
public function initialize()
{
$this->setSource('users');
$this->useDynamicUpdate(true);
}
public function beforeValidationOnCreate()
{
$this->createdAt = date('Y-m-d H:i:s');
}
public function beforeValidationOnUpdate()
{
$this->updatedAt = date('Y-m-d H:i:s');
}
}
Code to create the unnessary update.
$user = User::findFirstByEmail('[email protected]');
var_dump($user->country);
$user->email = '[email protected]';
$user->save();
This will result in the following two queries (ignoring the select).
UPDATE `users` SET `email` = '[email protected]', `updatedAt` = '2015-02-21 18:24:07' WHERE `userId` = '1'
UPDATE `countries` SET `updatedAt` = '2015-02-21 18:24:07' WHERE `countryId` = '1'
I have played around with the 'action' paramater on the relation passing constants from Phalcon\Mvc\Model\Relation but no change.
Any suggestions? :)