staudenmeir / eloquent-eager-limit-x-laravel-adjacency-list

Merge of staudenmeir/eloquent-eager-limit and staudenmeir/laravel-adjacency-list
MIT License
14 stars 1 forks source link

Column not found. #1

Closed marensas closed 1 year ago

marensas commented 1 year ago

Code:

use HasEagerLimitAndRecursiveRelationships;

    public function getPivotTableName(): string
    {
        return 'calculated_kpis';
    }

    public function getParentKeyName(): string
    {
        return 'from_kpi_id';
    }

    public function getChildKeyName(): string
    {
        return 'for_kpi_id';
    }

Command: Kpi::find(2557)->ancestors

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'laravel_cte.from_kpi_id' in 'on clause' (Connection: mysql, SQL: with recursive `laravel_cte` as ((select *, -1 as `depth`, cast(`id` as char(65535)) as `path` from `kpis` where `kpis`.`id` is null) union all (select `kpis`.*, `depth` - 1 as `depth`, concat(`path`, ., `kpis`.`id`) from `kpis` inner join `laravel_cte` on `laravel_cte`.`from_kpi_id` = `kpis`.`id`)) select * from `laravel_cte` where `laravel_cte`.`deleted_at` is null).

When using only laravel-adjacency-list works fine.

staudenmeir commented 1 year ago

Hi @marensas, The package doesn't support graph relationships yet, but I'm working on that.

staudenmeir commented 1 year ago

Do you need to apply a limit to a graph relationship (e.g. ancestors) or only to some of your own relationships?

marensas commented 1 year ago

Do you know need to apply a limit to a Graph relationship (e.g. ancestors) or only to some of your own relationships?

Currently I'm applying limit only to direct relationships. But I see usefull cases where limit could be applied to ancestors i.e. getting a tree with "latest" ancestors etc.

staudenmeir commented 1 year ago

I asked because I haven't found a solution for supporting limits on graph relationships yet.

However, I released a new version with the trait for graph relationships so you can at least apply limits to your direct relationships:

class Kpi extends Model
{
    use \Staudenmeir\EloquentEagerLimitXLaravelAdjacencyList\Eloquent\HasEagerLimitAndGraphRelationships;
}