cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Model::findFirst() must implement interface Phalcon\Mvc\ModelInterface or be null, instance of Phalcon\Mvc\Model\Row returned

Open TianLiangZhou opened this issue 6 years ago • 8 comments

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?

TianLiangZhou avatar Nov 18 '20 08:11 TianLiangZhou

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

kirill-voronov avatar Nov 22 '20 14:11 kirill-voronov

Please provide code example.

Jeckerson avatar Nov 22 '20 17:11 Jeckerson

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

TianLiangZhou avatar Nov 23 '20 09:11 TianLiangZhou

Please provide code example.

example:

$user = Users::findFirst([
 'id=1',
 'columns' => 'id, username'
]);

$user is Phalcon\Mvc\Model\Row instance

TianLiangZhou avatar Nov 23 '20 09:11 TianLiangZhou

 $user is Phalcon\Mvc\Model\Row instance

How to keep $user to be the instance of Users?

xaero7 avatar Nov 24 '20 06:11 xaero7

 $user is Phalcon\Mvc\Model\Row instance

How to keep $user to be the instance of Users?

Remove 'columns' => 'id, username' will.

TianLiangZhou avatar Nov 24 '20 07:11 TianLiangZhou

Resolved in #15220

zsilbi avatar Dec 01 '20 11:12 zsilbi

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

demkinmaxim avatar Mar 01 '21 09:03 demkinmaxim