Hi!
I use Phalocn 1.3.4 and it's ORM doesn't change value of the related model's field.
Example: I have 2 models. Page model:
<?php
namespace Common\Model;
class Page extends BaseModel
{
public $id;
public $name;
public $page_url;
public $meta_id;
public function initialize()
{
$this->hasOne('meta_id', 'Common\Model\Meta', 'id', [
'alias' => 'Meta'
]);
}
And Meta model:
<?php
namespace Common\Model;
class Meta extends BaseModel {
public $id;
public $meta_title;
public $meta_description;
public $meta_key_words;
}
Everything is simple, Page has one Meta
When I'm trying to create a Page everything is ok.
$page = new \Common\Model\Page();
$page->name = 'page\'s name';
$page->page_url = 'page\'s url';
$meta = new \Common\Model\Meta();
$meta->meta_title = 'page\'s title';
// an assignment of other fields
$page->Meta = $meta;
if (!$page->save()) {
// some action
}
But here something strange is going on when I want to update the meta of the page.
// First case
$page = \Common\Model\Page::findFirst("id='1'"); // Everything is ok
$page->Meta->meta_title = 'Some other title';
var_dump($page->Meta->meta_title); // shows old meta_title
$page->Meta->meta_description = 'Some other description';
var_dump($page->Meta->meta_title); // shows old meta_description again
$page->save(); // updates ONLY description!!! O_O.
// Second case
$page = \Common\Model\Page::findFirst("id='1'"); // Everything is ok
$page->Meta->meta_description = 'Some other description';
var_dump($page->Meta->meta_title); // shows old meta_description again
$page->Meta->meta_title = 'Some other title';
var_dump($page->Meta->meta_title); // shows old meta_title
$page->save(); // updates ONLY title!!! O_O.
So it saves the last assignment but ignores all the previous ones.
$page = \Common\Model\Page::findFirst("id='1'");
$meta = $page->Meta;
$meta->meta_title = 'Some other title';
$meta->save(); // Everything is ok.
It looks like a bug :(