Skip to content

Ambiguous clause when manually setting the parent_id on Category model #332

@Repox

Description

@Repox

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions