具有列聚合继承的symfony1枚举

时间:2013-06-25 11:40:03

标签: doctrine symfony-1.4

我有一个配置文件表,可以保存所有用户的所有配置文件。 我有不同类型的用户,并希望每种类型的用户都有不同的选择选项来选择某个字段 因此,两种用户类型都可以选择他们想要注册的时间,但是有不同的选项 - 一个可以选择2年而另一个可以选择。 schema.yml看起来像这样:

用户配置:

columns:
    username:
        type: string(255)
        notnull: true
        unique: false

WriterUserProfile:

inheritance:
    type: column_aggregation
    extends: UserProfile
columns:
    register_time:
        type: enum
        values:
            - 6 months
            - 1 year
            - 2 years
            - Other
        default: other

ReaderUserProfile:

inheritance:
    type: column_aggregation
    extends: UserProfile
columns:
    register_time:
        type: enum
        values:
            - 6 months
            - 1 year
            - Other
        default: other

出于某种原因,我无法选择“2年”选项 - 表单会出现“无效”错误 “2年”和“其他”是否相互重合,因为它们都是第三种选择?

1 个答案:

答案 0 :(得分:0)

还有其他不常见的领域吗?这一个字段仅仅不足以导致使用列聚合。无论如何,如果相同的字段出现在多个子类中,则字段应该向上移动,字段名称在所有相关类中都应该是唯一的(在您的情况下为UserProfile,WriterUserProfile,ReaderUserProfile)。

您可以在表单中更改选项字段的选项:

$choices = array('0' => 'a', '1' => 'b');
$this->getWidget('register_time')->setOption('choices', $choices);
$this->getValidator('register_time')->setOption('choices', array_keys($choices));