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
Active Record relation and asArray() #1402
Comments
Of course you can't use lazy loading with |
OK, I want to use eager loading, but I get error using that approach. When I query:
Without |
What error did you get? What's the error call stack? How are |
Here is my case:
When I load Driver model in Controller following way:
everything loads just fine, and I can see that cars are loaded. But when I want to load drivers with their cars as array:
I get error: Why I can't load related data as array. Sometimes it's crucial for applications. |
So after further investigation I've found out that there is simple fix. I've changed following function:
to
I've simply removed |
Thanks!!! |
If we have Model extending from ActiveRecord, we can easily query data as array using ActiveQueryTrait asArray() modifier. But when we have relation, for example (through PivotTable):
and now if we try to query data using lazy loading with asArray(), we won't have
items
at all. If we try to load related data using eager loading->with('items')
we will have error that we are usinggetDb() on non-object
.Any way to load ActiveRecord data as array and have related data in in associative array?
The text was updated successfully, but these errors were encountered: