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

发布于 2024-09-26 09:46:26 字数 658 浏览 1 评论 0 原文

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

想象一下:

NewsAuthor:
  inheritance:
    extends: sfGuardUser
    type:    simple

现在我想声明User_admin “nofollow">sfDoctrineGuardPlugin 成为我的新闻模型第一篇虚拟文章的作者。但如何做到这一点呢?

我尝试了以下操作:

NewsAuthor:
  AuthorAdmin:
    sfGuardUser: User_admin

但后来我收到了 doctrine:data-load 任务的错误:

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

我使用 Symfony 1.4.8 和 Doctrine 1.2.3。

谢谢您的期待,
莱米

I have a problem with the inheritance of Doctrine within my fixtures.yml file of Symfony.

Imagine the following:

NewsAuthor:
  inheritance:
    extends: sfGuardUser
    type:    simple

Now I want to declare the default guard user User_admin of the fixtures file of the sfDoctrineGuardPlugin to be the author of the first dummy article of my News model. But how to do this?

I tried the following:

NewsAuthor:
  AuthorAdmin:
    sfGuardUser: User_admin

But then I get this error of the doctrine:data-load task:

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

I use Symfony 1.4.8 with Doctrine 1.2.3.

Thank you in anticipation,
Lemmi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长梦不多时 2024-10-03 09:46:26

你误解了 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

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

You're misunderstanding how Doctrine's inheritance works. Under simple inheritance, NewsAuthor wouldn't have a reference to sfGuardUser, it would have all of the columns and relations that sfGuardUser has plus the ones you define. Inheritance is a bad approach here.

Instead, you want a NewsAuthor to have a reference to sfGuardUser. Your schema in this case would look like:

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

Your fixtures would then look as they did before:

NewsAuthor:
  AuthorAdmin:
    sfGuardUser: User_admin

You could then access the sfGuardUser object on a NewsAuthor object via $newsAuthor->User, similarly, you can access NewsAuthor on an sfGuardUser instance via $user->NewsAuthor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文