Closed AlirezaSedghi closed 1 year ago
Hello
Metas are not retrieved from database by default.
They're only loaded if you either used Model::with('metas')
or trying to access a meta.
But currently, with the eloquent query that I wrote, Laravel executed the following database queries to produce the result:
The picture above shows that 36500 MetaData models were loaded, using the following query for each one, even though I did not use "with('metas')":
select * from
people_metawhere
person_id= * and
person_idis not null
Send the code of your eloquent query builder and how you use it's result, so I can reproduce the issue. Does queries tab show the location and line where that query was performed?
Thanks to the helpful answers provided by @siamak2, I was able to identify the problem. The issue was caused by attempting to retrieve model attributes in the view. When attempting to retrieve a single attribute value of the model, all of its attributes were being fetched simultaneously.
Hi there,
I'm trying to load data without fetching any meta fields along with it. I've attempted to use the without method, but it's not working as expected. Here's the code I tried:
$people = Person::without(['metas'])->get();
Can you suggest an alternative solution or help me figure out why this approach isn't working?
Thank you.