将 Doctrine 与视图结合使用 - dud 'id'场生成

发布于 2024-09-15 10:05:02 字数 344 浏览 7 评论 0原文

我有一个数据库(是的,就是那个),事实证明通过视图访问它比原始表更容易访问。总的来说,这与 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 技术交流群。

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

发布评论

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

评论(2

梦过后 2024-09-22 10:05:02

我不知道如何在 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?

送舟行 2024-09-22 10:05:02

也许不完全是你问的但是
另一个解决方案是将其放入模型类中

public function setUp() {
    Doctrine_Core::getTable('your_view_name')->removeColumn('id');
    parent::setUp();
}

希望它可以帮助解决此问题的人

perhaps not exactly what you asked but
another solution is to put this in the model class

public function setUp() {
    Doctrine_Core::getTable('your_view_name')->removeColumn('id');
    parent::setUp();
}

hope it helps someone with this problem

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