使用YAML定义一对一关系



我进行了一个项目,该项目基于yaml。

我需要在两个实体之间创建一对多关系:帖子和图像(帖子可以为零或任何数量的图像)。

post.orm.yml:

TESTBundleBlogBundleEntityPost:
    type: entity
    table: null
    fields:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
        postUserId:
            type: integer
            column: post_user_id
        postDate:
            type: datetime
            column: post_date
        postContent:
            type: text
            column: post_content
        postTitle:
            type: string
            length: 255
            column: post_title
        commentStatus:
            type: boolean
            column: comment_status   
    oneToMany:
       images:
         targetEntity: Image
         mappedBy: pos
    lifecycleCallbacks: {  }

image.orm.yml

TESTBundleBlogBundleEntityImage:
    type: entity
    table: null
    fields:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
        filePersistencePath:
            type: string
        subDir:
            type: string
    manyToOne:
      pos:
        targetEntity: Post
        inversedBy: images
      joinColumn:
        referencedColumnName: id
    lifecycleCallbacks: {  }

probelm:当我更新数据库架构时,我会收到以下错误:

 [SymfonyComponentDebugExceptionContextErrorException]
 Notice: Undefined index: targetEntity in C:xampphtdocsbghitnvendordoct
 rineormlibDoctrineORMMappingDriverYamlDriver.php line 399

我不明白此消息。您的帮助总是很感激。

编辑:这是用-dump-sql

更新模式的结果
C:xampphtdocsbghitn>php app/console doctrine:schema:update --dump-sql
ALTER TABLE image ADD CONSTRAINT FK_C53D045F4B89032C FOREIGN KEY (post_id) REFER
ENCES post (id);
CREATE INDEX IDX_C53D045F4B89032C ON image (post_id)

从邮政实体中删除onetomany的关系,并保留图像实体中的许多关系

manyToOne:
  post:
    targetEntity: TESTBundleBlogBundleEntityPost
    joinColumn:
      name: post_id
      referencedColumnName: id

请注意凹痕。

最新更新