【问题标题】:Symfony 1.4 embedRelation where clauseSymfony 1.4 embedRelation where 子句
【发布时间】:2012-08-10 12:18:06
【问题描述】:

是否可以在 embedRelation 上设置 where 子句?

$this->embedRelation('treatedStones');

我需要得到处理过的石头,其中stone_free = 0

【问题讨论】:

    标签: symfony-1.4 symfony-forms doctrine-1.2


    【解决方案1】:

    我认为您无法使用 embedRelation 执行此操作,但您可以像在 sfFormDoctrine 中那样手动执行此操作。

    $subForm = new sfForm();
    
    // create a custom query e.g. in `TreatedStoneTable::queryFree($relatedId)` and
    // a method to the class of `$this->getObject()` to retrieve free stones 
    // e.g. `Class::getFreeTreatedStones()` to call the query
    foreach ($this->getObject()->getFreeTreatedStones() as $index => $childObject)
    {
      $form = new TreatedStoneForm($childObject);
    
      $subForm->embedForm($index, $form);
      $subForm->getWidgetSchema()->setLabel($index, (string) $childObject);
    }
    
    $this->embedForm('treated_stones', $subForm);
    

    您可以在docs 中找到有关表单工作原理的更多详细信息。

    【讨论】:

    • 我想发布相同的答案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    相关资源
    最近更新 更多