0

私はこのschema.ymlをゴスしました

Makeproduct:  
  actAs: 
    Timestampable: ~ 
  columns:  
    product_id:   { type: integer(8), notnull: true }  
    ingredient_id: { type: integer(8), notnull: true }  
    ingredient_quantity: { type: integer(8), notnull: true } 
    measure_id: { type: integer(8), notnull: false } 
   relations:  
    Product:
      local: product_id
      foreign: id
      foreignAlias: ProductIngredients 
    Ingredient:
      local: ingredient_id
      foreign: id
      foreignAlias: ProductIngredients 
    Measure:  
      local:         measure_id  
      foreign:       id 

Ingredient:
  actAs:
    I18n:
      fields: [name]
  columns:
    name: { type: string(50), notnull:true}
    price: { type: decimal, notnull:true}

Category:
  actAs:
    I18n:
      fields: [name]
  columns:
    name: { type: string(50), notnull:true}
  relations: 
    ProductsCategory:  
      class:        Product
      local:        id
      foreign:     category_id 
      type:         many 

Measure:
  columns:
    name: { type: string(2), notnull:true}
  relations: 
    ProductsCategory:  
      class:        Makeproduct
      local:        id
      foreign:     measure_id 
      type:         many 

Product:
  actAs:
    I18n:
      fields: [name, description]
      actAs:
        Sluggable: { fields: [name], uniqueBy: [lang, name] } 
  columns:
    category_id:   { type: integer(8), notnull: true }  
    name: { type: string(50), notnull:true}
    pic: { type: string(150)}
    description: { type: clob}
    price: { type: decimal, notnull:true}
  relations: 
    Ingredients:
      class: Ingredient 
      foreignAlias: Products 
      refClass: Makeproduct 
      local: product_id
      foreign: ingredient_id
    Category:  
      local:         category_id  
      foreign:       id 

このスキーマでフォームを作成してbuild--formsを起動しましたが、ProductFormをMakeproductFormとマージしたいと思います。これは、ProductFormにいるときに材料も入力して、現在の製品に接続できるようにするためです。 。

私はsymfonyのウェブサイトにあるこの例に従ってこれを行おうとしました、そして私は私のコードでこの変更を加えました:

MakeproductForm:

class MakeproductForm extends BaseMakeproductForm
{
  public function configure()
  {

  unset($this['created_at'], $this['updated_at']);

  $this->useFields(array('ingredient_id', 'ingredient_quantity', 'measure_id'));

  }
}

ProductForm:

class ProductForm extends BaseProductForm
    {
      public function configure()
      {

          $this->setWidgets(array(
          'id'               => new sfWidgetFormInputHidden(),
          'category_id'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Category'), 'add_empty' => false)),
          'pic'    => new sfWidgetFormInputFile(),
          'price'            => new sfWidgetFormInputText(),
          //'ingredients_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Ingredient')),      
        ));  

        $this->setValidators(array(
          'id'               => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
          'category_id'      => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Category'))),
          'pic'    => new sfValidatorFile((array('mime_types' => 'web_images','path' => sfConfig::get('sf_web_dir').'/images/', 'required' => false))),
          'price'            => new sfValidatorNumber(),
          //'ingredients_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Ingredient', 'required' => false)),    
        ));

        $this->widgetSchema->setNameFormat('product[%s]');

        $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);    

        $this->embedI18n(array('en', 'it'));
        $this->widgetSchema->setLabel('en', 'English');
        $this->widgetSchema->setLabel('it', 'Italian');

        //$this->mergeForm(new MakeproductForm(Doctrine::getTable('Makeproduct')->find($this->getObject()->getId())));


      $subForm = new sfForm();
      for ($i = 0; $i < 2; $i++)
      {
        $makeproduct = new Makeproduct();
        $makeproduct->Ingredient = $this->getObject();

        $form = new MakeproductForm($makeproduct);

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


      }

現在の問題は、製品のIDを認識せず、コストレインエラーが発生することです。

SQLSTATE [23000]:整合性制約違反:1452子行を追加または更新できません:外部キー制約が失敗します(dolcisymfonymakeproduct、CONSTRAINT makeproduct_product_id_product_idFOREIGN KEY(product_id)REFERENCES productid))

私は何かが欠けていると確信していますが、その例に従って問題を解決することはできず、これらの2つの形式をmrgeしてください:私にいくつかのヒントを与えてください。

4

1 に答える 1

1

あなたの問題はこの行に関するものだと思います:

$makeproduct->Ingredient = $this->getObject();

私は次のように見えるはずだと思います:

$makeproduct->Product = $this->getObject();
于 2012-06-22T16:47:30.757 に答える