0 votes

Received by email:
This is in regards to: http://support.orm-designer.com/556/feature-request-attributes-associations-should-doctrine2 Thanks so much for adding this support for us and the detailed example.

I have one question regarding it. Could you please provide an example of how this would work for many-to-many associations? I've tried various things to try and get custom attributes to export for these but can't seem to figure it out. Being able to put custom attributes in the owning and inverse sides of many-to-many relationships is the last scenario that we need for this.

in Solved by Skipper developer (137k points)
recategorized by

1 Answer

0 votes
Best answer

This feature is available in newest version 2.1.12.713 Here is info how this feature works.

We decided to implement two ways how to set custom attributes to ManyToMany element.

Based on a destination entity

The first method offers you to set custom values based on a destination entity. This means you will be able to edit these values when you select association leading from MN entity to Destination Entity.

enter image description here

If you want to configure orm properties in such way, simply add following XML snippet to your Doctrine2 configuration file

<struct name="ManyToManyEntity">
    <attribute name="custom-first" type="string"/>
    <attribute name="custom-second" type="string"/>
</struct>

Based on an Owner/Inverse side

The second method how you can configure ManyToMany custom attributes is by Owning/Inverse notation. To do that, choose MN object inside the Entity, choose required side and edit the property .

enter image description here

Here is an example of XML configuration to configure such behavior:

<struct name="ManyToMany">
    <struct name="side-owning">
        <attribute name="custom-owning" type="string"/>
    </struct>
    <struct name="side-inverse">
        <attribute name="custom-inverse" type="string"/>
    </struct>
</struct>

Comparison of both methods

Each of this solution has some advantages/disadvantages:
Destination-based settings
- it's easier to use than the second way
- property types are the same for both sides

Inverse/Owning-based settings
- need to understand Inverse/Owner side of MN association
- ability to set different property types for each side

It's up to each user which solution is the best for him and what he choose. It's not a problem to combine both solutions in the same time.

One more improvement

The last improvement in ManyToMany export script is the ability to define custom attributes also for join-table element. To do this, insert following setting to your configuration:

<struct name="ManyToMany">
    <attribute name="custom-root" type="string"/>
</struct>

enter image description here

Export example

Support for this attribute is fully available for XML, YML and PHP annotations export. In case you will update ORM Designer configuration in the way described above, export files will contain following data:

<doctrine-mapping>
  <entity name="Table2">
    ...
    <many-to-many custom-second="custom-second" custom-owning="custom-owning" ...>
      <join-table name="Table1ToTable2" custom-root="custom-root">
            ...
      </join-table>
    </many-to-many>
  </entity>
</doctrine-mapping>

<doctrine-mapping>
  <entity name="Table1">
      ...
    <many-to-many custom-first="custom-first" custom-inverse="custom-inverse"/>
  </entity>
</doctrine-mapping>
by Skipper developer (137k points)
selected by