You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$model=Model::findFirst();
$res=$model->toArray();
if i want to covert to array by toArray() ,i get an error:
Table '' doesn't exist in database when dumping meta-data for Model
You need to check if your model is bound to the correct database table. Have a look at the initialize method of your model
class MyModel extends Phalcon\Mvc\Model
{
public function initialize()
{
$this->setSource('database_table');
}
}
The first error you get shows that you do not have a table defined there.
The findFirst returns back the model instance which indeed does not have the setHydrateMode in it. You can therefore use toArray() on it with optional field names passed (in the toArray) to get what you need.
If you have more results then you will get a resultset and setHydrateMode will return back arrays.
Describe the bug
$model=Model::findFirst();
$res=$model->toArray();
if i want to covert to array by toArray() ,i get an error:
Table '' doesn't exist in database when dumping meta-data for Model
doc https://docs.phalcon.io/4.0/en/db-models#hydration-modes
if i run this example
$model=Model::findFirst();
$model->setHydrateMode(
Resultset::HYDRATE_ARRAYS
);
the error is
The method 'setHydrateMode' doesn't exist on model
Details
Phalcon version:4.0 rc2
PHP Version: 7.3.11
Operating System: ubuntu
The text was updated successfully, but these errors were encountered: