akeneo / pim-community-dev

[Community Development Repository] The open source Product Information Management (PIM)
http://www.akeneo.com
Other
952 stars 516 forks source link

No parent_id field in database on overrided entity Category #3578

Closed igormukhingmailcom closed 8 years ago

igormukhingmailcom commented 8 years ago

Hi.

I've added new fields via overriding Category entity as described here: http://docs.akeneo.com/master/cookbook/category/add-properties-to-category.html

But when I trying to run pim:install - I have next result:

Load jobs for fixtures. (data set: PimInstallerBundle:icecat_demo_dev)
Load fixtures. (data set: PimInstallerBundle:icecat_demo_dev)
  > loading [1] Pim\Bundle\InstallerBundle\DataFixtures\ORM\LoadCurrencyData
  > loading [2] Pim\Bundle\InstallerBundle\DataFixtures\ORM\LoadLocaleData
  > loading [15] Pim\Bundle\InstallerBundle\DataFixtures\ORM\Base\LoadRoleData
  > loading [16] Pim\Bundle\InstallerBundle\DataFixtures\ORM\Base\LoadGroupData
  > loading [100] Pim\Bundle\InstallerBundle\DataFixtures\ORM\LoadFixturesData
An error occured during the fixtures execution.
Error #0 in class Doctrine\DBAL\DBALException: An exception occurred while executing 'SELECT t1.id AS id2, t1.code AS code3, t1.created AS created4, t1.root AS root5, t1.lvl AS lvl6, t1.lft AS lft7, t1.rgt AS rgt8, t1.visibility AS visibility9, t1.weight AS weight10, t1.parent_id AS parent_id11 FROM CustomCategory t1 WHERE t0.code = ? LIMIT 1' with params ["master"]:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 't1.parent_id' in 'field list'

Entity CustomCategory overrides Category right way, but field parent_id not in database for unexpected reason, only id, code, created, root, lvl, lft, rgt and my custom fields there.

<?php

namespace Application\PimCatalogBundle\Entity;

use Pim\Bundle\CatalogBundle\Entity\Category as BaseCategory;

class CustomCategory extends BaseCategory
{
...
}

Can anyone help me, please? Thanks.

judomu commented 8 years ago

Same problems here. What i get after recreating the database is the following schema:

MyCategory

I guess it should be only one table with a "self-reference" (like the old pim_catalog_category has got).

Within the import job the generated query SELECT t1.id AS id2, t1.code AS code3, t1.created AS created4, t1.root AS root5, t1.lvl AS lvl6, t1.lft AS lft7, t1.rgt AS rgt8, t1.description AS description9, t1.parent_id AS parent_id10 FROM MyCategory t1 WHERE t0.code = ? LIMIT 1 is causing the exception from above (its generated in BasicEntityPersister.php/load(...)).

igormukhingmailcom commented 8 years ago

@julmuell Yes, have exactly same tables structure, without parent_id on custom table. WDYT, this is Doctrine issue?

juliensnz commented 8 years ago

Hello guys,

Did you override the orm mapping ? You should have this:

Application\PimCatalogBundle\Entity\Category:
    type: entity
    table: pim_catalog_category
    fields:
        description:
            type: text
            nullable: true

And added this key to the DI:

parameters:
    pim_catalog.entity.category.class: Application\PimCatalogBundle\Entity\Category

Regards

igormukhingmailcom commented 8 years ago

Hi, @juliensnz. Yes, sure. With no result. I've resolve this issue by fully copy-pasting parent entity and adding new fields right into copied one - so I've got a big file with lot of fields :). After this I have two tables (new one and parent one that not using anymore), but it at least working...

nidup commented 8 years ago

Hi @igormukhingmailcom and @julmuell !

You're right, there is an issue in the 1.4 documentation, thank you very much for the feedback!

We've fixed the doc in this Pull Request https://github.com/akeneo/pim-docs/pull/190/files (we'll deploy it soon on our official doc).

The missing part is the following one:

+You also need to configure the mapping override in your application configuration (to avoid to copy/paste the whole parent class mapping):
 +
 +.. code-block:: yaml
 +
 +    # app/config/config.yml
 +    akeneo_storage_utils:
 +        mapping_overrides:
 +            -
 +                original: Pim\Bundle\CatalogBundle\Entity\Category
 +                override: Acme\Bundle\AppBundle\Entity\Category

This part configures the automatic copy/paste of parent class mapping.

We've enhanced it in 1.4 by introducing the mapping_overrides configuration, we've properly updated the cookbook http://docs.akeneo.com/latest/cookbook/catalog_structure/overriding_the_orm_product_value.html but we've missed this conf in the category override cookbook.

BTW, if you encounter any typo or issues with the doc, do not hesitate to open a Pull Request to contribute on https://github.com/akeneo/pim-docs

Please let me know if it solves your issue, thx! :)

igormukhingmailcom commented 8 years ago

Hi, @nidup! Thank you very much :)