alirezabahram7 / bfilter

12 stars 5 forks source link

in bfilter when i add id in my relation "message": "SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select count(*) as aggregate from `packages` where `client_app_id` = 0 and (exists (select * from `categories` inner join `categorizables` on `categories`.`id` = `categorizables`.`category_id` where `packages`.`id` = `categorizables`.`categorizable_id` and `categorizables`.`categorizable_type` = App\\Models\\Package and `id` = 21 and `categories`.`deleted_at` is null)) and `packages`.`deleted_at` is null)", #22

Closed saber13812002 closed 2 years ago

saber13812002 commented 2 years ago

I have a relation between package Model and Categories Table with Categorizable relation

after that, I added this migration

        Schema::table('categorizables', function (Blueprint $table) {
            **$table->id()->before('category_id');**
            $table->integer('order')->after('categorizable_type')->default(0);
            $table->integer('weight')->after('order')->default(0);
        });

after that this filter broken:

https://debug.behaminplus.ir/survey-service/api/v1/packages/templates?filter=%7B%22filters%22%3A%5B%5B%7B%22field%22%3A%20%22category_id%22,%20%22op%22%3A%20%22%3D%22,%20%22value%22%3A21%7D%5D%5D%7D

{"filters":[[{"field": "category_id", "op": "=", "value":21}]]}

/api/v1/packages/templates?filter={"filters":[[{"field": "category_id", "op": "=", "value":21}]]}

error is this "message": "SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select count(*) as aggregate frompackageswhereclient_app_id= 0 and (exists (select * fromcategoriesinner joincategorizablesoncategories.id=categorizables.category_idwherepackages.id=categorizables.categorizable_idandcategorizables.categorizable_type= App\\Models\\Package andid= 21 andcategories.deleted_atis null)) andpackages.deleted_atis null)",

saber13812002 commented 2 years ago

just rename category_id in my filter to id:

{"filters":[[{"field": "ïd", "op": "=", "value":21}]]}

Alireza recommended that if you choose the relation field in your relation B filter can detect it