1

I'm using Doctrine2 to extend an Entity. The main entity is so defined:

    /**
 * ERP_Articoli
 * @ORM\Table(name="erp_articoli", indexes={
 *      @Index(name="search_company", columns={"company"}),
 *      @Index(name="search_codfam", columns={"codice_famiglia"}),
 *      @Index(name="search_codgrumer", columns={"codice_gruppo_merceologico"}),
 *      @Index(name="search_tipologia", columns={"tipologia"}),
 *      @Index(name="search_flagpuweb", columns={"flag_pubblica_web"}),
 *     })
 * @Gedmo\SoftDeleteable(fieldName="deletedAt")
 * @ORM\Entity(repositoryClass="MyCompanyBundle\Repository\ERP_ArticoliRepository")
 * @CompanyAware(companyFieldName="company")
 *
 * @ORM\InheritanceType("SINGLE_TABLE")
 *
 */
class ERP_Articoli

While the extended entity starts like this

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Index;
use MyCompanyBundle\Entity\ERP_Articoli as BaseErpArticoli;

/**
 * ERP_Articoli
 *
 * @ORM\Entity(repositoryClass="MyCompanyExtendedBundle\Repository\ERP_ArticoliExtendedRepository")
 * @ORM\Table(indexes={@Index(name="search_codfamweb", columns={"codice_famiglia_web"})})
 */
class ERP_ArticoliExtended extends BaseErpArticoli

Now I want to add another index to the resulting table "erp_articoli" but I can't figure out how to do that. The tag @ORM\Table(indexes={@Index(name="search_codfamweb", columns={"codice_famiglia_web"})}) won't do anything (not even errors)...How to achieve my goal?

Ale TheFe
  • 1,540
  • 15
  • 43
  • Why did you declare your ERP_ArticoliExtended to be a MappedSuperclass, not an entity? – lxg Oct 09 '18 at 07:55
  • If I extend an entity to integrate the new fields to the old ones, don't I have to declare it as MappedSuperclass? If no I am missing something about what MappedSuperclass() stands for! – Ale TheFe Oct 09 '18 at 08:16
  • A MappedSuperclass is the *parent* of an entity class. The entity *inherits from* the super class, not the other way round. – lxg Oct 09 '18 at 09:45
  • OK, thanks, now I got it. This doesn't solve my problem though! I've updated my code – Ale TheFe Oct 09 '18 at 09:49
  • Have you cleared your cache and updated your database schema? If so, you should now have a new table ERP_ArticoliExtended. – lxg Oct 09 '18 at 09:54
  • OK, my goal is different: I don't want a table named "erp_articoliextended", I want a table "erp_articoli" with both the fields of the 2 entities – Ale TheFe Oct 09 '18 at 12:10
  • I would recommend you to thoroughly read SF’s docs on inheritance mapping. – lxg Oct 09 '18 at 13:03
  • @AleTheFe Hi, did you found any solution? – user2342558 May 11 '22 at 10:26

0 Answers0