Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming a relation in Doctrine 2 ORM?

How can i set the name of the foreign key (edit: not the name of the attribute itself) for the many-to-one relation "region" using YAML?

SWA\TestBundle\Entity\Province:
  type: entity
  table: province
  uniqueConstraints:
    UNIQUE_PROVINCE_CODE:
      columns: code
  id:
    id:
      type: integer
      generator: { strategy: AUTO }
  fields:
    code:
      type: integer
    name:
      type: string
      length: 255
    short_name:
      type: string
      length: 2
  manyToOne:
    region:
      targetEntity: Region
      inversedBy: provinces
like image 593
gremo Avatar asked Oct 02 '11 00:10

gremo


1 Answers

Look at the getCreateConstraintSQL method in the AbstractPlatform class to see how the name of the foreign key is chosen (line 1088).

It is taken directly from the constraint name. Influencing constraint name will influence the foreign key name.

As a workaround you could drop the constraint and re-create it with a new name in a doctrine migration.

like image 110
Jakub Zalas Avatar answered Sep 23 '22 15:09

Jakub Zalas