php-activerecord icon indicating copy to clipboard operation
php-activerecord copied to clipboard

count(): Parameter must be an array or an object that implements Countable in ActiveRecord\Model::find_by_pk() (line 1670 of php-activerecord/lib/Model.php)

Open explod3r opened this issue 7 years ago • 9 comments

count(): Parameter must be an array or an object that implements Countable in ActiveRecord\Model::find_by_pk() (line 1670 of php-activerecord/lib/Model.php) PHP 7.2

explod3r avatar Feb 08 '18 11:02 explod3r

I have the same problem

nurmuhammet-ali avatar May 15 '18 14:05 nurmuhammet-ali

same are there solutions ?

salvatorelapi avatar May 18 '18 07:05 salvatorelapi

you can hack use Model::first(['id' => $id]) instead of Model::find($id) :))

Axu1g avatar May 21 '18 14:05 Axu1g

not an option if table has more than one primary key and you need more than one result. My solution 1670 line of Model.php: if ($results != ($expected = count((array)$values)))

explod3r avatar May 21 '18 15:05 explod3r

yes, just a small hack that worked for me, until your PR is not merged

Axu1g avatar May 21 '18 15:05 Axu1g

Currently dealing with this on a site that I want to update from PHP 7.1 => 7.2. I'm pulling in php-activerecord/php-activerecord via composer currently and cannot hack the core to fix this.

natenolting avatar Jan 31 '19 19:01 natenolting

Hi. I am also pulling via composer. Looking forward for a fix. Thanks!

ajanini avatar Mar 27 '19 17:03 ajanini

Instead of modifying the core function you could also use: Model::find(array($id));

QuackBtz avatar Apr 11 '19 22:04 QuackBtz

also this variant working Model::find_by_id($id);

azazellolvv avatar Nov 06 '19 08:11 azazellolvv