views:

672

answers:

1

I am using Symfony 1.3.2 with Propel ORM on Ubuntu 9.10.

I have a user profile table, which has many other tables linked to it (i.e. user_profile.id is a FK in many other tables.

My db schema looks something like this:

user_profile:
  _attributes: { phpName: UserProfile }
  id: ~
  guard_id:  { type: integer, foreignTable: sf_guard_user, foreignReference: id, required: true }
  address:   { type: longvarchar, required: true }

vehicle_type:
  _attributes: { phpName: VehicleType }
  id: ~
  name: { type: varchar(32), required: true }


user_vehicle:
  _attributes: { phpName: UserVehicle }
  id: ~
  user_id:  { type: integer, foreignTable: user_profile, foreignReference: id, required: true }
  vehicle_type: { type: integer, foreignTable: vehicle_type, foreignReference: id, required: true }
  license_plate:     { type: varchar(16), required: true }


user_child:
  _attributes: { phpName: UserChild }
  id: ~
  user_id:  { type: integer, foreignTable: user_profile, foreignReference: id, required: true }
  gender:   { type: boolean, required: true }
  name:     { type: varchar(32), required: true }

I would like to embed the other objects that link to the user profile object, in the user profile form, so that when I am performing CRUD on a user profile form, the related objects (e.g. UserVehicle, UserJob are also CRUD at the same time as the user profile object).

I need a simple snippet that will show how to:

  1. Embed the various related objects (i.e. UserVehicle, UserChild) into the UserProfile form
  2. Create/Update/Delete the various related objects as the operation is being carried (please note, a user can have more than 0-N vehicles or children assigned to them
+1  A: 

Have you read the documentation?:

// lib/form/doctrine/ProductForm.class.php
public function configure()
{
  $subForm = new sfForm();
  for ($i = 0; $i < 2; $i++)
  {
    $productPhoto = new ProductPhoto();
    $productPhoto->Product = $this->getObject();

    $form = new ProductPhotoForm($productPhoto);

    $subForm->embedForm($i, $form);
  }
  $this->embedForm('newPhotos', $subForm);
}

For the create/delete/update part, this article might give some help.

Felix Kling