Model::findFirst() must implement interface Phalcon\Mvc\ModelInterface or be null, instance of Phalcon\Mvc\Model\Row returned
This error will appear after updating to 4.1. The reason is that I added the column field. If so, is Phalcon \ Mvc \ Model \ Row still useful?
https://github.com/phalcon/cphalcon/blob/3241d96e4bb01dc7746b74c9ce586250b8887c46/phalcon/Mvc/Model.zep#L1575 https://github.com/phalcon/cphalcon/blob/3241d96e4bb01dc7746b74c9ce586250b8887c46/phalcon/Mvc/Model.zep#L1601 https://github.com/phalcon/cphalcon/blob/3241d96e4bb01dc7746b74c9ce586250b8887c46/phalcon/Mvc/Model/Query.zep#L3654
@niden Return type of Phalcon\Mvc\Model::findFirst now must be ModelInterface, but it returns Phalcon\Mvc\Model\Query::execute which return type is mixed. In our project we use widely 'columns' option for findFirst, so that bug makes upgrading to 4.1 impossible
Please provide code example.
https://github.com/phalcon/cphalcon/blob/3241d96e4bb01dc7746b74c9ce586250b8887c46/phalcon/Mvc/Model.zep#L1575
https://github.com/phalcon/cphalcon/blob/3241d96e4bb01dc7746b74c9ce586250b8887c46/phalcon/Mvc/Model.zep#L1601
https://github.com/phalcon/cphalcon/blob/3241d96e4bb01dc7746b74c9ce586250b8887c46/phalcon/Mvc/Model/Query.zep#L3654
@niden Return type of Phalcon\Mvc\Model::findFirst now must be ModelInterface, but it returns Phalcon\Mvc\Model\Query::execute which return type is mixed. In our project we use widely 'columns' option for findFirst, so that bug makes upgrading to 4.1 impossible
I have upgraded, I have removed all columns
Please provide code example.
example:
$user = Users::findFirst([
'id=1',
'columns' => 'id, username'
]);
$user is Phalcon\Mvc\Model\Row instance
$user is Phalcon\Mvc\Model\Row instance
How to keep $user to be the instance of Users?
$user is Phalcon\Mvc\Model\Row instanceHow to keep
$userto be the instance ofUsers?
Remove 'columns' => 'id, username' will.
Resolved in #15220
And what about findFirst in the actual Model class?
I have BaseModel extends \Phalcon\Mvc\Model
And I get:
must be compatible with Phalcon\Mvc\Model::findFirst($parameters = NULL): ?Phalcon\Mvc\ModelInterface
Here is the code in 4.1.x branch after MR: https://github.com/phalcon/cphalcon/blob/f1315049b46c0e3d348c6446e592c071b901f011/phalcon/Mvc/Model.zep#L1575
Here was the fix: https://github.com/phalcon/cphalcon/blob/69d41b28c12e1817105f7180570bf4e79a5f5794/phalcon/Mvc/ModelInterface.zep#L107