logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

This is an old version of this answer!

Return to the current answer
Hi,

first thing is a little change in schema:

Contact:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
first_name: { type: string(50)}
last_name: { type: string(50)}



Phone:
columns:
id: { type: integer(5), primary: true, autoincrement: true }
contact_id: { type: integer(4) }
number: { type: string(20) }
type: { type: enum, values: [Home, Work, Cell, Fax] }
relations:
Contact: { foreignAlias: Phone, foreignType: one }


PhoneForm.class.php should be:


class PhoneForm extends BasePhoneForm
{
public function configure()
{
$this->useFields(array('number', 'type'));
}
}


and ContactForm.class.php:


class ContactForm extends BaseContactForm
{
public function configure()
{
$this->useFields(array('first_name', 'last_name'));

// embdding form
$phoneForm = new PhoneForm($this->getObject()->getPhone());
$this->embedForm('Phone', $phoneForm);
}
}


If you use
$this->embedRelation('Phone', 'PhoneEmbedForm');
Doctrine fetches Phone objects related with Contact object only for editing, so you can't create new Phone objects.

In case I showed above you are embedding a Phone form initialized with related Phone object
$this->getObject()->getPhone()
. If there is no related Phone object, then you can see a blank form for creating new object.

Pawel Dawczak | 10/19/10 at 6:49pm

This is an old version of this answer!

Return to the current answer