Skip to content
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

Set empty relations as loaded too and prevent unnecessary database queries. #116

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

mendicm
Copy link

@mendicm mendicm commented Sep 14, 2016

When accessing a relation via the magic __get method on Elasticquent loaded model, unnecessary queries to the datatabase are performed if the relation is empty,. For example:

$product = Product::search('product_slug')->first();
$properties = $product->properties;

If the properties related model (BelongsToMany relationship) is an empty array on ElasticSearch document the relation on the $product model isn't loaded and a query to the database is performed. With this fix we prevent this unnecessary queries.

…y on the elastic document. This prevents future queries when accessing the relationship via the magic __get method.
@mendicm
Copy link
Author

mendicm commented May 15, 2017

mmmm.... Hi?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant