Hello everyone, 

I am creating a complex form using the
ahDoctrineEasyEmbeddedRelationsPlugin to create forms containing many to
many relations.

The plugin seems to work fine when only using a tier 1 relation (Eg user
belongs to usergroup and vica versa).

But when I have a tier 2 or 3 relation (Eg A house has 4 floors and each
floor has 3 rooms and each room has 5 pictures of furniture) the
validation fails when editing the record, not when creating a new
record.

Some code:

Scheme.yml:

realestate:
  actAs: { Timestampable: ~ }  
  columns:
    id: { type: integer(9), primary: true, autoincrement: true }
    addressStreet:  { type: string(100), notnull: true, minlength: 2 }
    addressNr:  { type: string(10), notnull: true }
    adressBus:  { type: string(10)  }
  relations:
    realestateFloors:
      type: many
      class: realestateFloors
      local: id
      foreign: realestate_id
      onDelete: CASCADE

realestateRooms:
  columns:
    id: { type: integer(9), primary: true, autoincrement: true }
    lenght: { type: decimal, notnull: true }
    width: { type: decimal, notnull: true }
    height: { type: decimal, notnull: true }
    remarks: { type: string(2000) }
    floor_id: { type: integer(9) }
    type: { type: enum, notnull: true, values:
[Living,Badkamer,Keuken,Slaapkamer,Garage,Eetkamer,Bureauruimte,Terras,Tuin] }
  relations:
    realestateRoomPictures:
      type: many
      class: realestateRoomPictures
      local: id
      foreign: realestate_room_id
      onDelete: CASCADE

realestateRoomPictures:
  columns:
    id: { type: integer(9), primary: true, autoincrement: true }
    picture:  { type: string(255) }
    angle:   { type: enum, notnull: true, values: [RechtsBoven,
LinksBoven, RechtsOnder, LinksOnder, Enkel] }
    remarks: { type: string(1000) }
    realestate_room_id: { type: integer(9) }

realestateFloors:
  columns:
    id: { type: integer(9), primary: true, autoincrement: true }
    realestate_id: { type: integer(9) }
    floorNr: { type: integer(9), notnull: true }
    floorMap: { type: string(255) }
  relations:
    realestateRooms:
      type: many
      class: realestateRooms
      local: id
      foreign: floor_id
      onDelete: CASCADE

RealestateForm.class.php:

class realestateForm extends BaserealestateForm
{
  public function configure()
  {
    parent::configure();
    unset($this['created_at'], $this['updated_at']);
    
    //Embed One2Many relations
    'realestateFloors' => array(
      'considerNewFormEmptyFields'    => array('floorNr'),
      'noNewForm'                     => false,
      'newFormLabel'                  => 'New Floor',
      'displayEmptyRelations'         => false,
      'newFormAfterExistingRelations' => true,
      'formFormatter'                 => null,
      'multipleNewForms'              => true,
      'newFormsInitialCount'          => 1,
      'newFormsContainerForm'         => null, // pass BaseForm object
here or we will create ahNewRelationsContainerForm
      'newRelationButtonLabel'        => '+',
      'newRelationAddByCloning'       => true,
      'newRelationUseJSFramework'     => 'jQuery')
        
        ));
  }
}

realestateFloorsForm.class.php:

class realestateFloorsForm extends BaserealestateFloorsForm
{
  public function configure()
  {
    //hide the id field
    $this->widgetSchema['realestate_id'] = new
sfWidgetFormInputHidden();
        
    //Embed One2Many relations
    $this->embedRelations(array(    
    'realestateRooms' => array(
      'considerNewFormEmptyFields'    => array(),
      'noNewForm'                     => false,
      'newFormLabel'                  => 'New Room',
      'displayEmptyRelations'         => false,
      'newFormAfterExistingRelations' => true,
      'formFormatter'                 => null,
      'multipleNewForms'              => true,
      'newFormsInitialCount'          => 1,
      'newFormsContainerForm'         => null, // pass BaseForm object
here or we will create ahNewRelationsContainerForm
      'newRelationButtonLabel'        => '+',
      'newRelationAddByCloning'       => true,
      'newRelationUseJSFramework'     => 'jQuery')));

  }
}

realestateRoomsForm.class.php

class realestateRoomsForm extends BaserealestateRoomsForm
{
  public function configure()
  {
        $this->widgetSchema['floor_id'] = new sfWidgetFormInputHidden();
        
        //Embed One2Many relations
    $this->embedRelations(array(    
    'realestateRoomPictures' => array(
      'considerNewFormEmptyFields'    => array(),
      'noNewForm'                     => false,
      'newFormLabel'                  => 'New Picture',
      'displayEmptyRelations'         => false,
      'newFormAfterExistingRelations' => true,
      'formFormatter'                 => null,
      'multipleNewForms'              => true,
      'newFormsInitialCount'          => 1,
      'newFormsContainerForm'         => null, // pass BaseForm object
here or we will create ahNewRelationsContainerForm
      'newRelationButtonLabel'        => '+',
      'newRelationAddByCloning'       => true,
      'newRelationUseJSFramework'     => 'jQuery')));
  }
}

and getting error

realestateRooms > 0 > realestateRoomPictures > 0 > picture: Required.
      * realestateRooms > 0 > new_realestateRoomPictures > 0 > picture:
        Required.
      * new_realestateRooms > 0 > lenght: Required.
      * new_realestateRooms > 0 > width: Required.
      * new_realestateRooms > 0 > height: Required.
      * new_realestateRooms > 0 > new_realestateRoomPictures > 0 >
        picture: Required

Help would be very appreciated, 3 days lost
Thanks in advance

Firemonkey


Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to