0 votes

ORM Designer 2.1.6.678, MVC: Symfony2, ORM: Doctrine2

When defining a many-to-many associations on the same table (e.g. "Person" with the association being "Friend") and only defining an alias for the "First Entity", the exported mapping information are blank. If both aliases are defined, everything is fine, same when "Second Entity" is the only defined alias. The 1st entity seems to be the Inverse Side in Doctrine terminology so the mappedBy field is empty when the Owning Side is not there because it has no alias. The 1st entity then should become the Owning Side if I'm not mistaken.

Also, after reopening the minimal test case there is a superfluous column "SampleEntity_id" being auto-generated, when I delete it, save and reopen, it will be added again. What's the use?

Minimal test case: http://www.xup.in/dl,15169937/ManyToManySelf.zip/

in Solved by (3.6k points)
recategorized by

Problem with SampleEntity_id is caused by invalid many-to-many entity definition caused by bug in MN wizard. Both fields are wrongly attached to first association and second left empty. (It's also visible in XML, where both many-to-many-field elements are stored in one many-to-many-entity). This bug should be fixed and new version will be released as soon as we fix all other issues.

Regarding to the second issue with missing/ambiguous owner/inverse side. We're going to change "Owner" and "Inverse" side in MN dialog, so Owner will be always first with note which side is Owning and which Inverse. I'm not sure if it will be possible to implement changing sides when only Inverse side is filled and Owning not.

I think that will suffice. They are both interchangeable anyway but it's straightforward to support "only the first entity being set" rather than "only the 2nd".

You're right. Don't know why we internally choosed second entity as owner ;-).

After next searching and testing we have concluded that everything works fine in case of Owner/Invese side.
"First Entity" is correctly stored as the owner entity in ORM Designer and "Second Entity" as Inverse entity. The reason why it's necessary to fill the second alias (alias to Inverse side) and not the first alias (alias to Owner side) is that if you want define the owner side on Doctrine2 schema, you have to specify alias to the inverse side and vice versa. Without inverse alias isn't possible to define owner side of association.
I'm not sure if there is anything more we can do in ORM Designer except more suitable owner/inverse side description.

enter image description here

It doesn't look now like the first entity is the owner entity, though. The export says
" manyToMany:
Parent:
targetEntity: SampleEntity
mappedBy: "
when Parent is defined on the first entity. It should say "joinTables:" on the owning side. With other many-to-many associations that lead to other tables the first entity is correctly used as Owning Side.

The following image of the diff between an ORMD1 exported YAML and one from ORMD2 shows the swapped joinColumns as a result:
show full image
enter image description here

Could you please send me part or ORMD1 model where this association is defined? There is probably some problem in conversion self-MN relation from v1 to v2 project.

Regarding to your first sample, these are results I currently get:

Model:
enter image description here

enter image description here

When alias is defined for inverse entity schema is correctly exported:

Acme\DemoBundle\Entity\SampleEntity:
  type: entity
  fields:
    id:
      id: true
      type: integer
      generator:
        strategy: AUTO
    name:
      type: string
      length: 255
      nullable: true
  manyToMany:
    Parent:
      targetEntity: SampleEntity
      joinTable:
        name: Sample_Parent
        joinColumns:
          sample_entity_first_id:
            referencedColumnName: id
            nullable: false
        inverseJoinColumns:
          sample_entity_second_id:
            referencedColumnName: id
            nullable: false

enter image description here

When alias is defined only for owning side, ORM Designer export only partial definition of many to many association:

Acme\DemoBundle\Entity\SampleEntity:
  type: entity
  fields:
    id:
      id: true
      type: integer
      generator:
        strategy: AUTO
    name:
      type: string
      length: 255
      nullable: true
  manyToMany:
    Parent:
      targetEntity: SampleEntity
      mappedBy:  

enter image description here

If both aliases are defined, my schema now looks this:

Acme\DemoBundle\Entity\SampleEntity:
  type: entity
  fields:
    id:
      id: true
      type: integer
      generator:
        strategy: AUTO
    name:
      type: string
      length: 255
      nullable: true
  manyToMany:
    Child:
      targetEntity: SampleEntity
      inversedBy: Parent
      joinTable:
        name: Sample_Parent
        joinColumns:
          sample_entity_first_id:
            referencedColumnName: id
            nullable: false
        inverseJoinColumns:
          sample_entity_second_id:
            referencedColumnName: id
            nullable: false
    Parent:
      targetEntity: SampleEntity
      mappedBy: Child 

All these definitions looks correctly. It's possible that we fixed something when we searched for bug or we're missing something.

I am confused. I thought the owning side would hold the definition of the association. But it's fine, I switched all relations to define the alias on the second or inverse entity.

It's not a conversion issue, because the minimal test case sample yields exactly the same behavior.

2 Answers

+1 vote
Best answer

We sucesfully fixed all associations / many to many editors, rename all "from" and "to" fields to "owner" and "inverse". Here is how ORM Designer now works with associations and owner/inverse terminology.

We have following simple model:

Image caption

Association is defined like this:

Image caption

This is how association is stored in ORM Designer XML file:

 <association from="Address" to="Contact" caption="New association" owner-alias="addresses" inverse-alias="contact" uuid="ec89f366-2f22-44fa-a6e7-06b909cbc13e">
      <association-field from="contact_id" to="id"/>
</association> 

And model exported from this model will look like this:

 <entity name="Address">
    <id name="id" type="integer">
      <generator strategy="AUTO"/>
    </id>
    <many-to-one field="contact" target-entity="Contact" inversed-by="addresses">
      <join-columns>
        <join-column name="contact_id" referenced-column-name="id" nullable="false"/>
      </join-columns>
    </many-to-one>
  </entity>

  <entity name="Contact">
    <id name="id" type="integer">
      <generator strategy="AUTO"/>
    </id>
    <field name="name" type="string" length="255" nullable="true"/>
    <one-to-many field="addresses" target-entity="Address" mapped-by="contact"/>
  </entity>
by Skipper developer (141k points)
selected by

release for all platforms including other bugfixes will be available during one hour.

This issue was fixed in latest version 2.1.7.679. You can download this version here http://support.orm-designer.com/31/download-orm-designer2-here

0 votes

After I wrote short example explaining owner and inverse side I noticed that you're right with the bug in ORMD2. After all owner/inverse side refactorizations we made there is probably some inconsistency between GUI and core.

Give me a minute please, I need to check it more.

by Skipper developer (141k points)

Sure, take all the time you need. I have worked around it by moving all concerned aliases to the second entity. I just switched to ORMD2 in production and committed all entities and mapping info to dev trunk on our project. Works like a charm!

Thanks for all your support and understanding. We're doing some more improvements on GUI to make it more explicit. We changed terminology FROM and TO in Associations/MN wizards to Inverse/Owner. We're still testing whole app and ensuring that everything will works correctly now.

Unfortunately I'm afraid that some of changes you made in aliases you will have to revert on the next version. In some cases ORM Designer currently wrongly swap inverse and owner side.

enter image description here

Also we add "Inverse Entity" fields before "Owner Entity" fields in all dialogs to unify the whole behavior:

enter image description here

This field order change also solve our problem in MN and association editors where you need fill "second" alias. Required row will be placed as first and optional row as second.

Sweet! I am fully aware that I need to switch back once you've fixed the bug, but it's only 5 many-to-many associations and I couldn't wait to test the whole build process with ORM Designer 2. ;)