Which ORM to use with Symfony2? [closed]
Asked Answered
P

3

12

I'm starting a new project with Symfony2 and I'm not really sure which ORM to choose. I've heard some bad things about Doctrine2, especially when it comes to inheritance and DQL. It seems like Propel is back from the dead, but on the other hand, there's no warranty that it will last forever.

Do you have any advice ?

Psychomancy answered 2/11, 2011 at 11:34 Comment(1)
I remember when learning s1, I saw some alternatives listed in the tuts, and adopted a couple. I regretted it, b/c if the community uses e.g. Doctrine, all the blogxamples and SO commentary will revolve around Doctrine. So even if Propel were better suited (I don't know), D is still a better choice pragmatically.Microgroove
M
11

I can tell you Propel is the most suitable ORM to use with Symfony2. It works fine and no plan to stop activities on it. The Propel2 project is on its way to be better than Propel 1.6.x (which is ever really great).

Don't hesitate to use Propel, many users including Sensio Labs are using it !

Here is the Propel doc for Symfony2: http://www.propelorm.org/documentation/#working_with_symfony2

Note: There is a related topic on Stack Exchange: https://softwareengineering.stackexchange.com/questions/48760/should-i-choose-doctrine-2-or-propel-1-5-1-6-and-why/117078#117078

Some points I forgot:

  • Behaviors are part of Propel, no one provided in Doctrine2. That means Propel officially supports them and provides support/improvements. Not sure about Doctrine ones.
  • Propel is really fast. I agree Doctrine2 is better than Propel for mass insertions.
  • Propel is 10 years old, stable and used by a lot of people.
  • No yet another language to learn with Propel.
  • Propel2 is really object oriented, thanks to fluent APIs.
  • Doctrine2 ORM doesn't share the same API with ODM, so you may use Propel with D2 ODM like D2 ORM and ODM, there are no pros here.
  • Propel uses code generation for specific platforms, so it's optimized for your needs, and fast thanks to runtime & generator parts.

Some points I like in Doctrine2:

  • Annotations.
  • The whole code because it's quite recent.

The problem is not about Doctrine DBAL but more about Doctrine ORM. And Propel2 is on its way to improve the whole Propel 1.6.x code.

Oh, and I used Doctrine2 for a long time ;)

Mythomania answered 2/11, 2011 at 12:4 Comment(3)
That programmers.stackexchange.com question is about choosing ORM without any relation to framework. Just about choosing ORM as a standalone tool, as I understand.Larios
It's quite related as Symfony2 is agnostic. As I said, almost official bundles are agnostics as well and it's not a problem to use Doctrine ORM, ODM, Propel, Mandango, etc.Mythomania
You probably ought to disclose your affiliation with Propel in your post.Twocycle
E
4

My personal choice is Doctrine 2 for a few reasons:

  • Conceptually, it's very easy to understand. Working with entities and the entity manager is simple. I love how entities don't need to extend any base model class (like in Doctrine 1).

  • It's sort of the standard ORM for Symfony2 right now. While it may not be officially 'endorsed' by Symfony2, it's what most people are using, and therefore there's a wealth of information for it online. The value of this is tremendous.

You mention that you've heard "bad things about Doctrine2" - it's important that you realize no ORM is going to be perfect. I've run into some problems with it, but as long as you think creatively, you can find a solution. Sometimes that solution means writing raw SQL, no matter what ORM purists might say. I haven't run into any situation where I regretted using Doctrine 2.

I spent a lot of time looking at Propel, but I just didn't like how it worked. That's not to say it's a poorly programmed library, but for me personally it wasn't a good fit. But since every developer is different, the best advice I can offer is that you look at the documentation and usage examples for both libraries. Since you're going to be the one using it, and not us, you need to pick the library you think you'll benefit the most from.

Ethic answered 2/11, 2011 at 15:38 Comment(4)
Well.. Don't know where you saw the DataMapper DP is easier than the ActiveRecord approach. I agree entities are simple but too restrictive. The problem is when you want to build real things, you have to understand the complexity behind D2 and how it works which is not easy. ActiveRecord is quite simple even if you want to build complex stuffs.Mythomania
I'm familiar with ActiveRecord from Doctrine 1. I agree that it's simple to use, but there's plenty of cases where it's not as efficient as the data mapper pattern.Ethic
Give me a use case where DataMapper is more efficient that AR ? Did you try nested tree/set for instance?Mythomania
@Arms don't you think its the horrible way by doctrine2 to use DQL functions in query doctrine-project.org/2010/03/29/doctrine2-custom-dql-udfs.html i mean for every function i will have to add extend it first. its stupid.Monadnock
L
1

I can tell you Propel is the most suitable ORM to use with Symfony2 I should disagree. Doctrine2 is a native ORM for Symfony. It is contained in standard Symfony distribution available here: http://symfony.com/download

Symfony documentation describes working with Doctrine mostly, not Propel. So, I don't think Propel choice is too obvious. I think you should really weight the consequences. I'd prefer Doctrine.

Here is a list of options, supported by Propel bundle: http://www.propelorm.org/cookbook/symfony2/working-with-symfony2.html

Larios answered 2/11, 2011 at 12:43 Comment(6)
Nothing is native and Doctrine will be removed from the Symfony2 core (in 2.1 version), just read the last Fabien Potencier blog post.Mythomania
@William DURAND What blog are you referring to? Anyway, if even this is true, for now (2.x branch) Doctrine is surely native. And official documentation is about Doctrine, not any other ORM. Also, Doctrine's author, Jonathan H. Wage worked for Sensio Labs for some time.Larios
This one: fabien.potencier.org/article/49/what-is-symfony2 The doc isn't about Doctrine except for one chapter also documented for Propel. Great bundles are agnostics and work with Propel like a charm. I know Jonathan worked for SL, will you change your mind if they hire me ? I don't think so ;) I don't say Doctrine2 isn't suitable for Symfony2 but it's a pain to use in real life. Basic usages are ok but if you want to do more stuffs, it's quite hard.Mythomania
@William DURAND: Does it say anything about Doctrine being removed in 2.1? Did I miss this part? Fabien just says, that ORMs for Symfony are just optional dependencies.Larios
Yes, and it will be discussed tomorrow during the IRC meeting. I invite you to come. AFAIK Doctrine and Propel will be part of the Symfony2 "Bridge".Mythomania
@William DURAND Thanks for invitation. I've just noticed, that you are Propel lead developer. Anyway, I wish Propel be on equal terms with Symfony2. I wish documentation on using Propel with Symfony2 make its way into official documentation. Most important bundles are already available for Propel as well as Doctrine and I beleive with 2.1 Symfony will be true agnostic in this field. But currently at least documentation suffers from lack of Propel things.Larios

© 2022 - 2024 — McMap. All rights reserved.