Symfony - 关系n:m - sfWidgetFormPropelChoice

时间:2013-01-25 16:02:15

标签: widget symfony-1.4 propel

我直截了当地说;) 我在数据库中有这样的方案:

    <table name="kongres">
    <column name="id" type="integer" required="true" autoIncrement="true" primaryKey="true"/>
    <column name="is_actived" type="boolean" default="0"/>
    <column name="is_homepage" type="boolean" default="0"/>
    <column name="template" type="VARCHAR" size="50" required="true"/>
    <column name="produkt" type="integer" required="true"/>
</table>

<table name="menugroup">
    <column name="id" type="integer" required="true" autoIncrement="true" primaryKey="true"/>
    <column name="tytul" type="varchar" size="255"/>
</table>

<table name="kongresmenugroup">
    <column name="id" type="integer" required="true" autoIncrement="true" primaryKey="true"/>
    <column name="kongres_id" type="integer" required="true"/>
    <foreign-key foreignTable="kongres" onDelete="CASCADE">
        <reference local="kongres_id"
                   foreign="id"/>
    </foreign-key>
    <column name="menugroup_id" type="integer" required="true"/>
    <foreign-key foreignTable="menugroup" onDelete="CASCADE">
        <reference local="menugroup_id"
                   foreign="id"/>
    </foreign-key>
</table>

一旦正确的命令:symfony propel:build-model和symfony propel:build-forms我得到了一个表单(我添加并扩展了多个选项,因为我需要在子菜单中保存更多的会议) (后端):

     public function configure()
{

$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'kongres_id' => new sfWidgetFormPropelChoice(array('model' => 'Kongres', 'add_empty' => false, 'expanded' => true, 'multiple' => true)),
'menugroup_id' => new sfWidgetFormPropelChoice(array('model' => 'Menugroup', 'add_empty' => false)),
));

$this->setValidators(array(
'id' => new sfValidatorPropelChoice(array('model' => 'Kongresmenugroup', 'column' => 'id', 'required' => false)),
'kongres_id' => new sfValidatorPropelChoice(array('model' => 'Kongres', 'column' => 'id','multiple' => true)),
'menugroup_id' => new sfValidatorPropelChoice(array('model' => 'Menugroup', 'column' => 'id','multiple' => true)),
));

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

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


}

现在我的问题,好像我点击SAVE它将数据保存到数据库,但它们不正确,它总是写入字段:menugroup_id - &gt; 1和kongres_id - &gt; 1,例如,尽管国会选择ID = 21并且ID菜单等于例如3请告诉我我做错了什么因为我已经迷路了; /谢谢!

顺便说一句。抱歉我的英文;)

1 个答案:

答案 0 :(得分:0)

这是因为您在表单中的外键上有'multiple' => true,其值正保存到1;外键关系不理解此表单控件发送的数组 将multiple更改为false,或更改架构,以便kongres_id和menugroup_id不是外键。