【问题标题】:Doctrine generate models - problem with relation type学说生成模型 - 关系类型的问题
【发布时间】:2011-06-01 15:11:33
【问题描述】:

我正在尝试从 yaml 架构生成学说模型

我有这样的架构:

Product:
    columns:
        id:
            type: integer(5)
            primary: true
            unsigned: true
            autoincrement: true
        activation_time:
            type: datetime
            notnull: true
        enduser_id:
            type: integer(5)
            unsigned: true
            notnull: true
    relations:
        Enduser:
            foreignType: one
            type: one
            foreignAlias: Product

Hostid:
    columns:
        id:
            type: integer(5)
            primary: true
            unsigned: true
            autoincrement: true
        value:
            type: string(32)
            fixed: true
            notnull: true

Order:
    columns:
        id:
            type: integer(5)
            primary: true
            autoincrement: true
            unsigned: true
        expire_date:
            type: datetime
        description:
            type: clob

Enduser:
    columns:
        id:
            type: integer(5)
            primary: true
            unsigned: true
            autoincrement: true
        hostid_id:
            type: integer(5)
            unsigned: true
            notnull: true
        order_id:
            type: integer(5)
            unsigned: true
            notnull: true
    relations:
        Order:
            foreignAlias: Endusers
        Hostid:
            foreignAlias: Endusers

问题是由学说 generate-models-yaml 生成的模型是错误的 在 BaseEnduser $Product 中定义为 Doctrine_Collection

$this->hasMany('Product', array( '本地' => 'id', '外国' => 'enduser_id'));

而只是 Product 对象

我做错了什么?

关系定义为 外国类型:一 类型:一个

【问题讨论】:

    标签: php doctrine models relation


    【解决方案1】:

    根据one-to-one example,您只需为“产品”做事

    relations:
        Enduser:
            foreignType: one
    

    IMO 其余的似乎都很好。无需定义其他内容,因为您仅将最终用户的引用与它的产品一起存储(以某种方式连接而不知道您想要做什么,用户不能拥有很多产品吗?反之亦然?)

    【讨论】:

    • 这就是问题所在,我按照你写的(foreignType: one)做了,但它不起作用;(
    • 你有没有可能创建数据库并让 Doctrine 为你生成模型/yml?听起来很愚蠢,但这样一来,您就可以看到错误所在。
    • 我解决了。我使用 2 个空格而不是制表符,一切顺利。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 2015-03-06
    • 1970-01-01
    相关资源
    最近更新 更多