简体   繁体   English

主义ORM加盟

[英]Doctrine ORM JOINS

I have a few simple classes, all extending Doctrine_Record. 我有一些简单的类,都扩展了Doctrine_Record。

Now I want to make a slightly more complex query with Inner Join, not just table data extracting. 现在,我想使用内部联接进行一个稍微复杂的查询,而不仅仅是表数据提取。

I am doing to use DQL, does this oblige me to manually define relation between 2 tables? 我正在使用DQL,这是否使我不得不手动定义2个表之间的关系? Should I define this relation class or I better update schema.yml and somehow re-generate class code? 我应该定义这个关系类还是更好地更新schema.yml并以某种方式重新生成类代码?

No DQL joins are possible without such explicit relation preparations, right? 没有这种明确的关系准备就不可能进行DQL连接,对吗?

I would regenerate class code. 我将重新生成类代码。 I find its always good practice to use either schema or db as the authoritative source and then just regenerate and/or use migrations. 我发现将模式或db用作权威源,然后重新生成和/或使用迁移,这始终是一种很好的做法。 ITs easier to maintain things that way. IT人员更容易以这种方式进行维护。 Same goes for Propel as well as Doctrine. Propel和教义也一样。

You can add the relation to your .yaml file and then re-generate your classes that way. 您可以将关系添加到.yaml文件,然后以这种方式重新生成类。 Here's Doctrine's documentation on relations in Yaml files. 这是有关Yaml文件中关系 Doctrine文档。

You will need to re-generate your db so Doctrine can add the correct foreign key constraints based on the new relationships. 您将需要重新生成数据库,以便Doctrine可以基于新关系添加正确的外键约束。 This is relatively simple using the command line Doctrine command and assumes you don't care about losing your data. 使用命令行Doctrine命令 ,这相对简单,并且假定您不关心丢失数据。 If you do care about losing data, you should be using Doctrine to manage your migrations for you but that's beyond the scope of your question. 如果您确实担心丢失数据,则应使用Doctrine为您管理迁移,但这超出了您的问题范围。 You can find more info about the migrations by looking at A Frankel's answer to this question . 您可以查看A Frankel对这个问题的回答,找到有关迁移的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM