We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Problems with model

I don't know, but now I just cannot get records from the DB with find() (I return that result). With other models it works. Did anyone had that issue before?



98.9k
edited Sep '14

Could you please elaborate your question? Are you getting errors? Returned result is malformed?



33.8k

I get an empty object. I had checked every part of the route from start to beginning, but it just returns an empty array (that's the only thing that fails). There isn't any data that is deleted or similar.

It's strange, because if I return a string from the method, it works well. And I've two records in the DB for testing, but nothing.



33.8k

Ok, this is the second time I get a contrarious behaviour with Phalcon, and it's strange (the first one was when validating the other days).

Explain me why this works with one model, and why not with two:

public function get()
{
    return Model::find();
}

Because in the second I need to do this:

public function get()
{
    $models = array();

    foreach (Model::find() as $model)
    {
        $models[] = $model;
    }

    return $models;
}


98.9k

Could you please post your code somewhere? (Github). I think it's hard to replicate at this moment.



33.8k

I cannot do it now. But it isn't very hard to replicate: just create two different models, and inside them, a function that do return Model::find(). Then call it with AJAX.