将 Doctrine 与视图结合使用 - dud 'id'场生成
我有一个数据库(是的,就是那个),事实证明通过视图访问它比原始表更容易访问。总的来说,这与 Doctrine 配合得很好,但有一个问题。当从数据库模式生成 YAML 时,Doctrine 无法识别视图表中的主键,因此它发明了一种称为“id”的主键。由此生成类意味着所有查询都会因缺少此 id 字段而失败。
有什么方法可以提示生成器脚本它不应该创建此字段,并将其指向更合适的字段吗?我可以看到如何在 YAML 或带有注释的类中执行此操作,但无法在数据库中执行此操作。
欢迎提出建议。
(任何关注我的问题(为什么?)的人可能都会明白我对 Doctrine 和这个数据库有多么有趣。我认为这被称为“学习体验”。)
I have a DB (yes, that one) which is proving far easier to access via views than raw tables. In general this plays quite nicely with Doctrine, but there's one issue. Doctrine can't identify a primary key in a view table when generating the YAML from the database schema, so it invents one called 'id'. Generating classes from this means that all queries fail on the lack of this id field.
Is there any way you can hint to the generator script that it shouldn't create this field, and point it to one that's more appropriate? I can see how to do it in the YAML, or in a class with annotations, but no way to do it in the DB.
Suggestions welcome.
(Anyone following my questions (why?) will probably have worked out how much fun I'm having with both Doctrine and this database. I think it's called a "learning experience".)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道如何在 YAML 中执行此操作,但您可以从生成的 PHP(基本)文件中删除 ID 列的定义。这不是最“优雅”的解决方案,但我认为 Doctrine 的惯例是始终添加主键。
顺便说一句,有什么对您有用的 http://www.doctrine-project.org/projects/orm/1.2/docs/manual/component-overview/en#views?
I have no idea how to do it in the YAML but you can just remove the the definition of the ID column from the generated PHP (Base) file. Not the most "elegant" solution but I think Doctrine's convetnion is to always add a Primary Key.
BTW, is there anything usefull for you at http://www.doctrine-project.org/projects/orm/1.2/docs/manual/component-overview/en#views?
也许不完全是你问的但是
另一个解决方案是将其放入模型类中
希望它可以帮助解决此问题的人
perhaps not exactly what you asked but
another solution is to put this in the model class
hope it helps someone with this problem