![]() |
Hi everyone,
I have code like this: PHP Code: $notifications = model(NotificationSettingModel::class)->withScheduleNotification()->find($userIds); after running it, i got an error like this: Code: array_column(): Argument #1 ($array) must be of type array, App\Entities\NotificationSetting given even though in version 4.4.8 the code above runs fine. but why doesn't it work on version 4.5.1? i took an example from this repositori: https://github.com/lonnieezell/forum-exa...t.php#L121 Thanks All.
@xxxx[{::::::::::::::::::::::::::::::::>
In top file strict_types=1 ?
(06-03-2024, 10:36 PM)warcooft Wrote: after running it, i got an error like this: array_column() does not accept an object. So if it works in 4.4.8, there is something wrong with 4.4.8. https://www.php.net/manual/en/function.array-column.php You must pass an array to array_column(). (06-04-2024, 05:48 PM)kenjis Wrote:(06-03-2024, 10:36 PM)warcooft Wrote: after running it, i got an error like this: i dont know why this is not working. before upgrading to version 4.5.1 the code ran smoothly, in aboove repository it was also clear that the NotificationSettingModel model returned an Entity class then used with array_column() function. This code also shows the entity as parameter in array_column function. See https://github.com/lonnieezell/forum-exa...ry.php#L61
@xxxx[{::::::::::::::::::::::::::::::::>
> in aboove repository it was also clear that the NotificationSettingModel model returned an Entity class then used with array_column() function.
No, no. It returns an array of Entities, not an Entity class instance. (06-04-2024, 07:39 PM)kenjis Wrote: > in aboove repository it was also clear that the NotificationSettingModel model returned an Entity class then used with array_column() function. Ok now I understand a bit, if I use the $model->find([1,2,3]); this method will return an entity object and if I use $model->whereIn('user_id', [1,2,3])->findAll( ); this will return an array of Entities. right? Anyway, using the second method was solved my case.
@xxxx[{::::::::::::::::::::::::::::::::>
Looks like this is a bug:
Different behavior between models with primary key ID and not ID or something else when using find() method. ![]() ![]() in NotificationSettingModel I use user_id as $primary_key and UserModel uses id as $primary_key it looks like the find() method uses id as the default reference. why doesn't the find() method detect the primary key assigned to the model? it would be more efficient than having to create chained methods like this model(NotificationSettingModel::class)->whereIn(user_id, [1,2,3])->findAll(); ------------------------------------------------------- PHP Code: $notifications = model(NotificationSettingModel::class)->find([4, 6]); The query above produces the same output as in the screenshot, is it because the method does not find the ID column in a table? my expected output is It should returns an array of Entities. ![]() after I debug again. the result query of this code model(NotificationSettingModel::class)->withScheduleNotification()->find([1, 2]); meets my expectations, but why is the output object an entity, not an array of an entity?
@xxxx[{::::::::::::::::::::::::::::::::>
> but why is the output object an entity, not an array of an entity?
I don't know, find([...]) should return an array. I cannot reproduce the result.
Try with this migration, this only happens if the primary key is not an id as in general, then create 1 dummy data and run query builder method llike model(NotificationSettingModel::class)->find([1,2]);
PHP Code: <?php here Entities: PHP Code: <?php Models: PHP Code: <?php
@xxxx[{::::::::::::::::::::::::::::::::>
|
Welcome Guest, Not a member yet? Register Sign In |