Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Active Record relation and asArray() #1402
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
Any way to load ActiveRecord data as array and have related data in in associative array?
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:
I've simply removed