franzose/ClosureTable

ancestorsWithSelf() queries database for each ancestor

mefenlon opened this issue · 0 comments

Having a similar issue to #231.

Using v6.1.1 on laravel/framework v8.26.1

    public function getLinkIdsAttribute()
    {
        return $this->ancestorsWithSelf()->get()->pluck('indextag_id')->implode('.');
    }

I end up with hundreds of queries that result from the above code

select * from `subjects` inner join `subject_closure` on `ancestor` = `subjects`.`id` where `descendant` = 61125 and `depth` = 0

Is there a way to eager load the ancestors or a better way of plucking these ids?

Thank you for your time and consideration. Your package is fantastic.