-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Entity::toArray() only converts Entity objects to array, not other objects #7643
Comments
Yes, this is is the expected behavior, specially since there is a vast amount of objects that cannot be converted to arrays in a sane way. What where you trying to do? |
I was trying to use extract from a result set. From some associated tables, actually. Something like:
There are timestamp fields in all of these tables, and those seem to be causing the problem. Update: I wasn't sure if I could use the {_} twice, so I tried to extract from Edit: I just saw your reply, sure I'll get back to you, |
Could you use a real example and the data you used? I'm failing to see the problem here. |
This is my actual code:
Here is the SQL: [link removed] |
I have not tried to reproduce this issue, but thinking in a situation in which:
$hashtags = $user_collection->extract('pinterest_accounts.{_}.pinterest_boards.{_}.hashtag');
Will return a Collection of datetime objects, then toList method must not convert Time objects into array, but generate an array of Time objects, no? |
@mylux I'm not entirely sure what Time objects have to do with it, since there is no time object in the hashtag field. But even when I tried something simpler, like extract('username'), I get the same error. |
@waltervos I think the problem is that you are passing the collection an array that is actually a dictionary, not an iterable array. Can you try this?
|
Good point, @lorenzo ! |
Huh, that does it, thanks! Edit: Really, thanks a lot 💯 |
@waltervos alternatively you can do this: $hashtags = collection($user-> pinterest_accounts)->extract('pinterest_boards.{*}.hashtag'); |
I ran into this issue as I was trying to convert a query result to a collection (
new Collection($result->toArray())
) and then trying toCollection::extract()
. When I follow that with aCollection::toList()
orCollection::toArray()
call, I get the following error:As far as I can see, this is because of
Cake\I18n\Time
objects present in the collection. These don't get converted to an array inEntity::toArray()
.I hope this is just my failure to grasp the workings of collections fully ;), but otherwise I think we should make sure that other objects get converted to array values as well.
The text was updated successfully, but these errors were encountered: