如何在fixtures.yml文件中声明Doctrines继承?

时间:2010-10-03 21:10:40

标签: php symfony1 doctrine yaml

我在Symfony的fixtures.yml文件中继承了Doctrine的问题。

想象一下:

NewsAuthor:
  inheritance:
    extends: sfGuardUser
    type:    simple

现在我想声明sfDoctrineGuardPlugin的fixtures文件的默认防护用户User_admin是我的新闻模型的第一个虚拟文章的作者。但是怎么做呢?

我尝试了以下内容:

NewsAuthor:
  AuthorAdmin:
    sfGuardUser: User_admin

但是我得到了doctrine:data-load任务的错误:

Unknown record property / related component "sfguarduser" on "NewsAuthor"

我将Symfony 1.4.8与Doctrine 1.2.3一起使用。

感谢您的期待,
利宝

1 个答案:

答案 0 :(得分:1)

你误解了Doctrine的继承是如何运作的。在简单继承下,NewsAuthor不会引用sfGuardUser,它会包含sfGuardUser所有的所有列和关系以及您定义的列。继承是一种不好的方法。

相反,您希望NewsAuthor具有对sfGuardUser的引用。在这种情况下,您的架构如下所示:

NewsAuthor:
  columns:
    user_id:
      type: integer(4)
      notnull: true
      unique: true #if one-to-one correspondence
  relations:
    User:
      class: sfGuardUser
      local: user_id
      foreignType: one

然后你的装置看起来像以前一样:

NewsAuthor:
  AuthorAdmin:
    sfGuardUser: User_admin

然后,您可以通过sfGuardUser访问NewsAuthor对象上的$newsAuthor->User对象,类似地,您可以通过{{NewsAuthor个实例访问sfGuardUser 1}}。