candy-api icon indicating copy to clipboard operation
candy-api copied to clipboard

Ambiguous clause when manually setting the `parent_id` on Category model

Open Repox opened this issue 5 years ago • 0 comments

Expected Behavior

When setting the Category model attribute parent_id and save the model, the attribute should be persisted.

Current Behavior

When trying set the Category model attribute parent_id and save the model, it throws an error message:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select `categories`.* from `categories` inner join `category_channel` on `categories`.`id` = `category_channel`.`category_id` and `category_channel`.`channel_id` = 1 and date(`category_channel`.`published_at`) <= 2020-12-08 inner join `category_customer_group` on `categories`.`id` = `category_customer_group`.`category_id` and `category_customer_group`.`customer_group_id` in (1) and `category_customer_group`.`visible` = 1 where `categories`.`drafted_at` is null and `id` = 4 group by `category_channel`.`category_id` limit 1)

Possible Solution

Currently, I'm utilizing the NodeTrait method setParentId() instead. The model should however be able to persist the attribute correctly, without resorting to trait methods (IMHO).

Steps to Reproduce

$category->parent_id = ($parent_id > 0) ? $parent_id : null; //current category ID is 4, parent_id is suppose to be set to 1
$category->save(); // Results in previously described error message

Context (Environment)

The issue occured during an attempt to import categories from external source (ERP) and manually setting model primary key and parent ID.

Detailed Description

Possible Implementation

Repox avatar Dec 08 '20 08:12 Repox