sonata-project/SonataDoctrineORMAdminBundle — Issue #9: oneToMany relations without a join table don't persis
Author: arnaugm
Created: 2011-11-11 12:45:08+00:00
State: open

I would like to add the oneToMany relations in the entities edit screens.

I have, in example, these admin clsases:
PhoneTypeAdmin
PhoneNumberAdmin
and one PhoneType has many PhoneNumbers, so the PhoneNumber class has the foreing key pointing the PhoneType.

The PhoneTypeAdmin configureFormFields function looks like this:

public function configureFormFields(FormMapper $formMapper)
{
$formMapper
// fields
->add('name')
// oneToMany
->add('phoneNumbers', null, array(
'required' => false
))
;
}

With this, what I see in the PhoneType edit screen is a multiple select box with the list of PhoneNumbers, which is great.
The problem is that if I click a PhoneNumber and press the Update button, the relation is not persisted.

I have read about the owner and inversed roles in doctrine's relations and I think my .orm.yml files are correct.

The doctrine definitions are:

Examples\ExampleBundle\Entity\PhoneType:
type: entity
table: phone_types
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: SEQUENCE
name:
type: string
length: null
fixed: false
nullable: false
oneToMany:
phoneNumbers:
targetEntity: PhoneNumber
mappedBy: phoneType
lifecycleCallbacks: { }

Examples\ExampleBundle\Entity\PhoneNumber:
type: entity
table: phone_numbers
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: SEQUENCE
phoneNumber:
type: string
length: null
fixed: false
nullable: false
column: phone_number
manyToOne:
phoneType:
targetEntity: PhoneType
inversedBy: phoneNumbers
joinColumns:
phone_type_id:
referencedColumnName: id
lifecycleCallbacks: { }

Any idea of what I'm missing?

Thanks