0 votes

Hi,

I am currently trialling ORM Designer for use in my employment and found the following bug.

I have created a couple of tables and the @ORM\JoinColumn line in the owner entity is generated incorrectly. In ORM Designer I have defined the field properties in the entity editor as:

Field Name    Type       Size    PK    FK    AI    NN    UQ
asset         integer                  X           X

The association is listed as:

Type     Foreign Entity    Owner Alias    Inverse Alias    Caption         Destination Field    Source Field
Local    Asset             Events         Asset            Events Asset    id                   asset

In the properties for the asset field I have defined a column of "asset_id".

When ORM Designer posts the data to my export file it created the following join column annotation:

@ORM\JoinColumn(name="asset", referencedColumnName="asset_id", nullable=false)

I believe this is incorrect and the name field should be sourced from the column property, resulting in a join column annotation of:

@ORM\JoinColumn(name="asset_id", referencedColumnName="asset_id", nullable=false)

I realise I can manually fix this; however, it is occurring in many places throughout a complex ORM and it would be impractical to fix this on a regular basis.

in Solved by (150 points)
recategorized by

2 Answers

0 votes
Best answer

We receive example model with the probable reason why you're getting this error.

ORM Designer example model

When you check your association (double click on "nextTest" caption), you will see that alias for inverse entity is missing:

ORM Designer association editor with missing alias

Doctrine2 uses aliases to describe owner/inverse side of association and without inverse alias there is no way how to export the association definition pointing from inverse owner side to inverse side.

When you enter aliases correctly:

Correctly entered alias in association editor

ORM Designer exports your association in correct way:

<?xml version="1.0"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Task">
    <id name="task_id" type="integer">
      <generator strategy="AUTO"/>
    </id>
    <field name="name" type="string" length="255" nullable="true"/>
    <one-to-one field="nextTask" target-entity="Task" inversed-by="nextTask">
      <join-columns>
        <join-column name="next_task_id" referenced-column-name="task_id" nullable="false" unique="true"/>
      </join-columns>
    </one-to-one>
    <one-to-one field="previousTask" target-entity="Task" mapped-by="nextTask"/>
  </entity>
</doctrine-mapping>

instead of original invalid

<?xml version="1.0"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Task">
    <id name="task_id" type="integer">
      <generator strategy="AUTO"/>
    </id>
    <field name="name" type="string" length="255" nullable="true"/>
    <one-to-one field="nextTask" target-entity="Task"/>
  </entity>
</doctrine-mapping>

You always need to enter alias leading to inverse entity, it's a primary direction. When you do that, you will get one-way association. If you enter also alias leading to owner entity, you will get two-way association.
Unfortunately it isn't possible to enter alias only to owner entity, because Doctrine2 stores all necessary information in direction OwnerEntity->InverseEntity.

I hope this post helps to clarify your questions.

by Skipper developer (136k points)
selected by
0 votes

Hi,

thank you for your question. It's strange that ORM Designer exports such code. Could you please share some example project where this error occures?

We already have a lot of users who use Doctrine2 annotations without any problems. I suppose the problem is somewhere inside the association definition.

Maybe one reason which comes to my mind. Can you check that you have correctly defined owner and inverse side of your association? Because each association has to lead from owner (where is assetid defined) to inverse (where is PK field, usually ID). But in your code you're trying to connect "asset" and "assetid". In this case "asset" has to be primary key of your entity.

Thank you for cooperation and best regards
Ludek

by Skipper developer (136k points)

From what I can tell everything is properly defined.

Am I able to send the XML file to a support address to see if you can replicate the problem?

Sure, please send your XML to [email protected] . Thanks!