We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Can't get relation when use custom columns

I try to get the relation but when i use custom columns it doesn't work, for example


    public function initialize(){
            ['alias' => 'genres']


$movies = Movies::find(["limit" => "10"]);
foreach ($movies as $movie){
    var_dump($movies->genres); // WORKS

$movies = Movies::find(["columns" => "id, title", "limit" => "10"]);
foreach ($movies as $movie){
    var_dump($movies->genres); // DOESN'T WORK :C

What can i do?, i don't need all columns for example in this case i just need the title, but also need the genres.



I think you should do like this, no? :

        $movies = Movies::find(array(
                "columns" => array("id, title"),
                "limit" => "10")

or using [...] notation, but encapsulating your column names too

edited Aug '16

You can't do it because you don't have full object returned. Using columns will return Phalcon\Mvc\Model\Row, it doesn't know anything abotu your model not your model. Just return full models if you want to use relatins or use query builder. I prefer this second option.

Yeah, the problem is that i don't need all the columns, in this moment im using raw SQL, but i want to know if i could do it with models without bring all columns.