[bug] Bogus extra fields added for indices in Doctrine 2

+1 vote
asked Dec 1, 2014 in Solved by rleuthold (130 points)
edited Dec 1, 2014 by ludek.vodicka

enter code hereIf I specify some indices manually, like this:

* @ORM\Table(
*     name="sys_config",
*     indexes={@ORM\Index(name="bundle", columns={"bundle_name"})},
*     uniqueConstraints={@ORM\UniqueConstraint(name="constant", columns={"bundle_name","const_name"})}
* )
* @ORM\Entity

... import the entity to Skipper, and export it to the ORM without applying any changes, Skipper adds extra field definitions for the columns specified in the indices:

/**
 * @ORM\Column(nullable=true)
 */
 private $const_name;

/**
 * @ORM\Column(nullable=true)
 */
 private $bundle_name;

although the field definitions already exist:

/**
 * @var string
 *
 * @ORM\Column(type="string", length=255, nullable=false, name="bundle_name")
 */
 private $bundle;

/**
 * @var string
 *
 * @ORM\Column(type="string", length=40, nullable=false, name="const_name")
 */
 private $constant;

Am I doing something wrong?

commented Dec 1, 2014 by ludek.vodicka Skipper developer (140,450 points)

Thanks for reporting. This is not the feature but definitely the bug. Obviously there is some problem in import or export. We will check it and let you know

2 Answers

0 votes
answered Dec 2, 2014 by ludek.vodicka Skipper developer (140,450 points)

Hi,

we made a deeper analysis of this problem and the reason for this invalid behavior is inside the Skipper index definitions where currently it isn't possible to make indexes on columns which aren't defined as fields.

In you case it should be sufficient to remove @columns={"bundlename"} from @indexes and @uniqueConstraints because you already have defined columns inside @ORM\Column(...name="bundlename").

Can you please try it and let me know?

commented Dec 2, 2014 by rleuthold (130 points)

Hi Ludek

Thank you for looking into this. Yes, that works and I understand the cause.

Unfortunately I can not change the database field names. It would be great to have a fix for this in an upcoming release.

commented Dec 2, 2014 by ludek.vodicka Skipper developer (140,450 points)

You're right. This invalid import behavior will be fixed in the next release.

As temporary fix to keep correct database/field names, it should be sufficient to remove redundant object fields nammed as database columns.

example

In your case it's bundle_name and const_name. This works for me here, so hope it will help you too.

(Also you will have to manually remove variables private $bundle_name; from your code because Skipper never remove anything except annotations)

0 votes
answered Nov 5, 2015 by ismavolk (150 points)

Same problem here.

My annotation is:

/**
 * Mcd01Mercadoria
 *
 * @ORM\Table(name="mcd01_mercadoria", uniqueConstraints={@ORM\UniqueConstraint(name="uk_codint", columns={"mcd01_codint"})}, indexes={@ORM\Index(name="idx_descricao", columns={"mcd01_descricao"}), @ORM\Index(name="ifk_mcd01_m11", columns={"adm01_unidade_mercadoria_id"}), @ORM\Index(name="ifk_mcd01_vasilhame", columns={"mcd01_mercadoria_vasilhame_id"}), @ORM\Index(name="ifk_mcd01_l07", columns={"fis11_ncm_id"}), @ORM\Index(name="fk_cfg02_clasmerc_nivel11_idx", columns={"cfg02_clasmerc_nivel1_id"}), @ORM\Index(name="fk_mcd01_mercadoria_dom04_sistematica_compra1_idx", columns={"dom04_sistematica_compra_id"}), @ORM\Index(name="fk_mcd01_mercadoria_prc01_familia_preco1_idx", columns={"prc01_familia_preco_id"}), @ORM\Index(name="dom24_tipo_entrega_mercadoria_id", columns={"dom24_tipo_entrega_mercadoria_id"}), @ORM\Index(name="dom24_tipo_entrega_mercadoria__2", columns={"dom24_tipo_entrega_mercadoria_id"}), @ORM\Index(name="mcd07_ingredientes_id", columns={"mcd07_ingredientes_id"}), @ORM\Index(name="fk_mcd01_dom24_idx", columns={"dom24_tipo_entrega_mercadoria_id"}), @ORM\Index(name="fk_mcd01_mcd07_idx", columns={"mcd07_ingredientes_id"})})
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks()
 * @ORM\Entity(repositoryClass="App\Entity\Mcd01MercadoriaRepository")
 */

And skipper add the indexes like fields with underlines.
Obs. My entities are generated by doctrine2 command line.

enter image description here

This bug have a solution?
Thanks

commented Nov 5, 2015 by ludek.vodicka Skipper developer (140,450 points)

Ok, I think this is a bug we have fixed yesterday ;-)

Can you please try following beta: https://support.skipper18.com/402/downloads-skipper-beta

Thanks!

...