Hi! There is some confusing behavior when using magic getters with newly created related records:
class Albums extends \Phalcon\Mvc\Model
{
public $id;
public $title;
public function initialize()
{
$this->hasMany('id', 'Songs', 'albums_id');
}
}
class Songs extends \Phalcon\Mvc\Model
{
public $id;
public $albums_id;
public function initialize()
{
$this->belongsTo('albums_id', 'Albums', 'id', array(
'alias' => 'Album',
));
}
}
$song = new Songs();
$album = new Albums();
$album->title = 'foo';
$song->album = $album;
$song->save();
// Next, we want to change song album's title to 'bar'.
// Let's pretend we haven't got $album in current context
// and have to get it from $song.
// Getting album this way its title stays "bar" after all next saves:
$album = $song->album;
// But with those methods albums.title reverts to "foo" after $song->save():
$album = $song->getAlbum();
$album = $song->getRelated('Album');
$album->title = 'bar';
$album->save();
// Here we got albums.title == 'bar' for every method
$song->save(); // Yes, for some reason we need to save song one more time.
// Here we got 'bar' for first one and 'foo' again for other two.
I think that magic properties and getters so as getRelated method too must behave identically, aren't they?