我在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一起使用。
感谢您的期待,
利宝
答案 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}}。