Projet SunshineAdminBundle

One to One and Many to One

Let’s start with a case :

We have project entity with a relation to a task entity. As our project can handle many tasks, we have defined in doctrine a relation One to Many.


How to do the mapping ?

3 steps.

1/ Configure parent and child entities using sunshine.

In order to declare this relation in sunshine, no real pain… This is the full file we are using to describe the project entity.

The relation has been defined in the attribute section.

If you have defined in your annotations a shorten path to the targetEntity class. You have to give to Sunshine the full path in the Yaml declaration using the relatedClass attribute..

2/ Define the filterAttribute field in the parent for the child.

The filterAttribute field is used to handle filter search, and is required for the mapping.

3/ Implement a toString into the child.

The target class, « Task » we also have to define a toString() method that the framework will use to render values in lists and forms.


This is enough for Sunshine to handle the mapping.



About the author

Eric Wallet

Add Comment

Click here to post a comment

Votre adresse de messagerie ne sera pas publiée.