PHP ORM:教义与推进

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2062473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:52:18  来源:igfitidea点击:

PHP ORMs: Doctrine vs. Propel

phpormsymfony1doctrinepropel

提问by Tom

I'm starting a new project with symfonywhich is readily integrated with Doctrineand Propel, but I of course need to make a choice.... I was wondering if more experienced people out there have general pros and/or cons for going with either of these two?

我正在用symfony开始一个新项目,它很容易与DoctrinePropel集成,但我当然需要做出选择......我想知道那里有更多经验丰富的人是否有普遍的优点和/或缺点这两个中的任何一个?

Thanks a lot.

非常感谢。

EDIT:Thanks for the all the responses, useful stuff. There's no truly correct answer to this question so I'll just mark as approved the one that got the most popular up-votes.

编辑:感谢所有的回复,有用的东西。这个问题没有真正正确的答案,所以我只会将获得最受欢迎票的那个标记为已批准。

采纳答案by phidah

I'd go with Doctrine. It seems to me that it is a much more active project and being the default ORM for symfony it is better supported (even though officially the ORMs are considered equal).

我会选择 Doctrine。在我看来,它是一个更加活跃的项目,并且作为 symfony 的默认 ORM,它得到了更好的支持(即使官方认为 ORM 是平等的)。

Furthermore I better like the way you work with queries (DQL instead of Criteria):

此外,我更喜欢您处理查询的方式(DQL 而不是 Criteria):

<?php
// Propel
$c = new Criteria();
$c->add(ExamplePeer::ID, 20);
$items = ExamplePeer::doSelectJoinFoobar($c);

// Doctrine
$items = Doctrine_Query::create()
       ->from('Example e')
       ->leftJoin('e.Foobar')
       ->where('e.id = ?', 20)
       ->execute();
?>

(Doctrine's implementation is much more intuitive to me).

(Doctrine 的实现对我来说更直观)。

Also, I really prefer the way you manage relations in Doctrine.

另外,我真的很喜欢你在 Doctrine 中管理关系的方式。

I think this page from the Doctrine documentation is worth a read: http://www.doctrine-project.org/documentation/manual/1_2/en/introduction:doctrine-explained

我认为 Doctrine 文档中的这个页面值得一读:http: //www.doctrine-project.org/documentation/manual/1_2/en/introduction: doctrine-explained

To sum up: If I were starting a new project or had to choose between learning Doctrine and Propel I'd go for Doctrine any day.

总结一下:如果我要开始一个新项目或不得不在学习 Doctrine 和 Propel 之间做出选择,我随时都会选择 Doctrine。

回答by Jan Fabry

I am biased, since I help a little bit on the next release of Propel, but you must consider that Propel was indeed the first ORM available, then lagged a bit when Doctrine got created, but now has active development again. Symfony 1.3/1.4 comes with Propel 1.4, where most comparisons stop at Propel 1.3. Also, the next release of Propel (1.5) will contain a lot of improvements, especially in the creation of you Criteria (resulting in less code for you to write).

我有偏见,因为我对 Propel 的下一个版本有所帮助,但是您必须考虑到 Propel 确实是第一个可用的 ORM,然后在创建 Doctrine 时滞后了一点,但现在又开始积极开发了。Symfony 1.3/1.4 与 Propel 1.4 一起提供,大多数比较在 Propel 1.3 处停止。此外,Propel (1.5) 的下一个版本将包含很多改进,特别是在创建您的标准方面(导致您编写的代码更少)。

I like Propel because it seems to be less complex than Doctrine: most code is in the few generated classes, whereas Doctrine has split up the functionality in lots of classes. I like to have a good understanding of the libraries I am using (not too much "magic"), but of course, I have more experience with Propel, so maybe Doctrine is not so complicated behind the scenes. Some say Propel is faster, but you should check this for yourself, and consider whether this outweighs other differences.

我喜欢 Propel,因为它似乎没有 Doctrine 复杂:大多数代码都在少数生成的类中,而 Doctrine 将功能拆分为许多类。我喜欢对我正在使用的库有一个很好的了解(没有太多的“魔法”),但是当然,我对 Propel 有更多的经验,所以也许 Doctrine 在幕后没有那么复杂。有人说 Propel 更快,但您应该自己检查一下,并考虑这是否超过了其他差异。

Maybe you should also consider the availability of Symfony plugins for the different frameworks. I believe Propel has an advantage here, but I don't know how many of the listed plugins are still up-to-date with the latest version of Symfony.

也许您还应该考虑 Symfony 插件在不同框架中的可用性。我相信 Propel 在这里有优势,但我不知道列出的插件中有多少仍然是最新版本的 Symfony。

回答by lo_fye

It comes down to personal preference. I use Propel because (among other things) I like the fact that everything has its own concrete getter & setter method. In Doctrine, this is not the case.

这归结为个人喜好。我使用 Propel 是因为(除其他外)我喜欢这样一个事实,即一切都有自己的具体 getter & setter 方法。在 Doctrine 中,情况并非如此。

Propel:

推进:

$person->setName('Derek');
echo $person->getName();

Doctrine:

教义:

$person->name = 'Derek';
echo $person->name;

The reason I like having getters & setters is that I can put all kinds of logic in them, if I need to. But that's just my personal preference.

我喜欢 getter 和 setter 的原因是,如果需要,我可以将各种逻辑放入其中。但这只是我个人的喜好。

I should also add that although Propel was slow-moving in the past, it is now under active development again. It has released several new versions in the past few months. The most recent version of Propel includes a "fluent query interface" similar to Doctrine's, so you don't have to use Criteria anymore if you don't want to.

我还应该补充一点,虽然 Propel 过去进展缓慢,但现在又在积极开发中。在过去的几个月里,它发布了几个新版本。最新版本的 Propel 包含一个类似于 Doctrine 的“流畅查询界面”,因此如果您不想,您不必再使用 Criteria。

回答by Bryan M.

It should be noted Doctrine 2is currently in developmentreleased[ed] and functions almost completely different from the current stable version of Doctrine 1. It relies on the Data Mapper pattern instead of Active Record, and uses an 'entity manager' to handle persistence logic. When released it will bear closer resemblance to Java's Hibernate (Doctrine 1 is more like Rails' ActiveRecord).

应当指出的学说2目前正在开发中发布[编者按]和功能几乎完全学说1.它依赖于数据映射模式,而不是活动记录的当前稳定版本不同,并使用“实体管理器”来处理持久逻辑。发布后,它将与 Java 的 Hibernate 更相似(Doctrine 1 更像 Rails 的 ActiveRecord)。

I've been developing with the alpha release of Doctrine 2, and must say it is heads and shoulders above Doctrine 1 (just my opinion, and I've never used Propel). Chances are good that the Doctrine community will move toward it when it's released.

我一直在开发 Doctrine 2 的 alpha 版本,并且必须说它比 Doctrine 1 高出不少(只是我的意见,我从未使用过 Propel)。当它发布时,Doctrine 社区很有可能会转向它。

I would encourage you to check out Doctrine, but if you prefer the Active Record style that Propel and Doctrine use now, you might want to just stick with Propel.

我鼓励您查看 Doctrine,但如果您更喜欢 Propel 和 Doctrine 现在使用的 Active Record 样式,您可能只想坚持使用 Propel。

回答by petkopara

I'd suggest to use propel 1.6 which is better for IDE's autocomplete function.

我建议使用 propel 1.6,它更适合 IDE 的自动完成功能。

回答by Mauricio Herrán

The two references are somewhat outdated so you nevertheless cover some generalities, basically you'd have to evaluate your experience with the framework as such, a major drawback to doctrine is the inability to have an IDE that lets you auto-code in that propel is a winner, learning curves propel and doctrine are very different, it is easier to propel, if your project will need to manage complex data model uses doctrine, if you want to work quickly with an ORM which is best documented and find more support in Propel Internet uses, is much more mature and I believe that most used.

这两个参考文献有些过时,因此您仍然涵盖了一些一般性,基本上您必须评估您对框架的体验,学说的一个主要缺点是无法拥有一个可以让您在该推进中自动编码的 IDE胜利者,学习曲线 propel 和学说非常不同,更容易推进,如果您的项目需要管理复杂的数据模型,请使用学说,如果您想使用文档最好的 ORM 快速工作并在 Propel 中找到更多支持上网用的,成熟的多,相信用得最多的。

http://propel.posterous.com/propel-141-is-out

http://propel.posterous.com/propel-141-is-out

回答by Ryan Rentfro

After using both of them for a number of years I prefer Propel 2 to Doctrine simply based on how you construct your query logic. Doctrine is as in depth as it can get and managing many aspects of it match that level of depth. Propel I feel has a more fluid and object driven way of building and managing the query interactions.

在使用它们多年之后,我更喜欢 Propel 2 而非 Doctrine,这只是基于您构建查询逻辑的方式。学说尽可能深入,并且管理它的许多方面都与该深度相匹配。我觉得 Propel 有一种更流畅和对象驱动的方式来构建和管理查询交互。

For me this led to less code in the model and more structures around how logic can/will be processed. This resulted in just building out many interactions as common functionality. (After all 90% of what you will do with a database is just going to be some degree of crud operation.)

对我来说,这导致模型中的代码更少,并且围绕如何/将如何处理逻辑的结构更多。这导致只是将许多交互构建为通用功能。(毕竟,您对数据库所做的 90% 都将是某种程度的 crud 操作。)

In the end, both are powerful, manageable and will get the job done. My personal projects and interest use Propel ORM 2 and future projects, if still written in PHP will go that route.

最后,两者都是强大的、易于管理的,并将完成工作。我的个人项目和兴趣使用 Propel ORM 2 和未来的项目,如果仍然用 PHP 编写会走那条路。

I've been using both on a daily basis for the past 3-4 years.

在过去的 3-4 年里,我每天都在使用这两种方法。

回答by Trav L

I'm not a user of PHP 5 non-framework ORM, but here's some good comparison posts (in case you haven't seen them yet):

我不是 PHP 5 非框架 ORM 的用户,但这里有一些很好的比较帖子(以防您还没有看到它们):

http://codeutopia.net/blog/2009/05/16/doctrine-vs-propel-2009-update/

http://codeutopia.net/blog/2009/05/16/doctrine-vs-propel-2009-update/

http://trac.symfony-project.org/wiki/ComparingPropelAndDoctrine

http://trac.symfony-project.org/wiki/ComparingPropelAndDoctrine

Both conlusion favorite towards Doctrine as a newer generation of ORM for Symfony.

这两个结论都喜欢作为 Symfony 的新一代 ORM 的 Doctrine。

回答by Mike Crowe

I'd suggest using DbFinder Plugin. This is actually a very powerful plugin that supports both, and is quite a nice powerful. I actually like using it better than either.

我建议使用DbFinder Plugin。这实际上是一个非常强大的插件,两者都支持,而且非常强大。我实际上更喜欢使用它。

回答by c9s

If I'm not wrong, both ORMs use XML-based schema, and creating these schema definition is pretty cumbersome. If you need a PHP-based simple schema with fluent style. You may try LazyRecord https://github.com/c9s/LazyRecordit supports automatic migration and upgrade/downgrade script generators. And all the class files are generated statically without runtime cost.

如果我没记错的话,两个 ORM 都使用基于 XML 的模式,并且创建这些模式定义非常麻烦。如果您需要具有流畅风格的基于 PHP 的简单模式。你可以试试 LazyRecord https://github.com/c9s/LazyRecord它支持自动迁移和升级/降级脚本生成器。并且所有的类文件都是静态生成的,没有运行时成本。