You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Preface: I'm still working on my first Statamic site, so I don't have a super great grasp of the inner workings yet. 😄
If you create your own models there's nothing preventing you from adding relations on the Entry model.
Would it be possible then to create a taxonomy relationship and I guess a pivot if require. Rather than storing taxonomies in the entry by handle you could grab them by ID.
public function categories()
{
$categoryIds = $this->data['categories'] ?? [];
return Taxonomy::whereIn('id', $categoryIds)->get();
}
I think this approach would end up being situational though because the data column doesn't know that categories is a taxonomy without referencing some other tables.
Activity
ryanmitchell commentedon Feb 3, 2023
At the moment
with()doesn't do anything in the Eloquent Entry Query builder.See:
eloquent-driver/src/Entries/EntryQueryBuilder.php
Line 84 in 83d4616
maxi032 commentedon Feb 3, 2023
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 commentedon Oct 2, 2024
I am experiencing large performance issues with taxonomies. I now see that "with" is not implemented. This is not going to be implemented?
ryanmitchell commentedon Oct 2, 2024
There are no plans to implement it.
adampatterson commentedon Mar 8, 2025
Would it mess things up if we stored the taxonomy IDs with the entry instead of handles?
I think that would allow for a taxonomy relationship to the Entry model.
ryanmitchell commentedon Mar 8, 2025
Not sure I’m following what you mean?
adampatterson commentedon Mar 8, 2025
Preface: I'm still working on my first Statamic site, so I don't have a super great grasp of the inner workings yet. 😄
If you create your own models there's nothing preventing you from adding relations on the Entry model.
Would it be possible then to create a taxonomy relationship and I guess a pivot if require. Rather than storing taxonomies in the entry by handle you could grab them by ID.
I think this approach would end up being situational though because the data column doesn't know that categories is a taxonomy without referencing some other tables.
ryanmitchell commentedon Mar 8, 2025
A term ID is just the slug/handle prefixed with the taxonomy handle. So you could do this as is.
Longer term I'm hoping some changes in core will allow this driver to use proper pivot tables.