Phalcon: Model relationships with Namespaces -
i'm trying set models namespaces. part's simple. it's relationship part i'm having tough time with.
i have these 2 models (these stripped down):
<?php namespace my\app\v1\models; class movies extends \my\namespace\path\base { } ?> <?php namespace my\app\v1\models class genres extends \my\namespace\path\base { public function initialize() { $this->hasmany('id', 'movies', 'genre_id'); } public function howmanymovies() { homecoming $this->countmovies(); } } ?>
so... is, give me:
cannot redeclare class my\app\v1\models\movies ....
so, started thinking has namespaces. so... alter hasmany to:
$this->hasmany('id', 'my\\app\\v1\\models\\movies', 'genre_id');
i can set backslashes in front end of "my" or not, either way get:
the method "countmovies" doesn't exist on model "my\app\v1\models\genres"
i seek changing line to:
return $this->countmyappv1modelsmovies();
... rather verbose, whatever. still "method doesn't exist" error.
what missing?
ok. after much time of trying figure out, 5 minutes after posting, it....
one must utilize alias:
$this->hasmany('id', 'my\\app\\v1\\models\\movies', 'genre_id', ['alias'=>'movies']);
i'll leave here else may need it.
model namespaces phalcon magic-function
No comments:
Post a Comment