Skip to content

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

Open
mendicm wants to merge 8 commits into
elasticquent:masterfrom
mendicm:master
Open

Set empty relations as loaded too and prevent unnecessary database queries.#116
mendicm wants to merge 8 commits into
elasticquent:masterfrom
mendicm:master

Conversation

@mendicm

@mendicm mendicm commented Sep 14, 2016

Copy link
Copy Markdown

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

mendicm commented May 15, 2017

Copy link
Copy Markdown
Author

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