statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
108 stars 78 forks source link

How to eager load relations? #119

Open maxi032 opened 1 year ago

maxi032 commented 1 year ago

I try to load a page and the associated taxonomies terms of it but the problem is that extra queries are being done. I am using Statamic multisite. I would like to be able to eager load only those associated with that specific entry. So I have a tags taxonomy and I want something like:

$queryBuilder = Entry::with(['tags'])->query()
->where('collection','pages')
->where('slug', 'my-page')
->where('site', 'en');
->where('published', true)->get();

Many thanks

ryanmitchell commented 1 year ago

At the moment with() doesn't do anything in the Eloquent Entry Query builder.

See: https://github.com/statamic/eloquent-driver/blob/83d461614d1967036e0d0ec1dd069e3ce3d82e42/src/Entries/EntryQueryBuilder.php#L84

maxi032 commented 1 year ago

I thought so... this takes away one of the greatest advantages of using Laravel, the fact that I can load related content basically on the fly.

de-raaf-media commented 1 month ago

I am experiencing large performance issues with taxonomies. I now see that "with" is not implemented. This is not going to be implemented?

ryanmitchell commented 1 month ago

There are no plans to implement it.