Home > Web Applications > Using Doctrine 1.1 with Symfony 1.2

Using Doctrine 1.1 with Symfony 1.2

I recently started a new project using the Symfony PHP Framework. I’ve used Symfony before and love it. In the past I’ve used Propel, but as Symfony now fully supports Doctrine and Doctrine looks very promising, I decided to give it a shot for my latest project.

Symfony 1.2 currently uses Doctrine 1.0. Doctrine 1.1 was released in March. Symfony 1.3 will support Doctrine 1.1, but won’t be released until November.

Since I’m starting a new project, I wanted to try to use the latest version of Doctrine. I’ll be honest, I don’t have a great reason for doing this other then the pain I went through migrating an old project (with lots of custom model stuff) from Propel 1.2 to Propel 1.3. I understand this is an apples to oranges comparison, however its the only motivation I’ve got. Feel free to stop reading now.

Overall the Symfony developers have made it extremely easy to use Doctrine 1.1 with Symfony 1.2. However, given this is an unsupported configuration, they don’t back-port any patches related to Doctrine 1.1 from the Symfony 1.3 branch to sf 1.2. In this post I will try to catalog the changes and provide a back-port patch you can use to integrate Doctrine 1.1 into your sf 1.2 projects.

Related Postings

Here are some pages/tickets/changesets related to Doctrine 1.1 with Symfony. If I’m missing something, please leave me a comment below and I’ll update this ASAP!

Symfony Blog Call the expert: Using a custom version of Doctrine
Ticket 5667 In generated forms, Doctrine 1.1 does not save model after linking relations.
Ticket 5741 CLI doesn’t use the right installation of Doctrine
Ticket 6285 Form generator, saving linked objects problem (SF 1.2 + Doctrine 1.1)
Changeset 16508 fix for admin gen and Doctrine 1.1 link()/unlink() methods (fixes #5667, #6285)
Ticket 6373 sfDoctrineGuardPlugin support Doctrine 1.1

Installing Doctrine 1.1

To get started using Doctrine 1.1, you’ll need to download it. Jonathan Wage provided instructions here which I’ll reproduce below.

From your Symfony project’s root folder:

$ cd lib/vendor
$ svn co http://svn.doctrine-project.org/branches/1.1/lib doctrine

Now change the location of the Doctrine lib path by editing your ProjectConfiguration::setup() method to look similar to:

public function setup()
{
  sfConfig::set('sfDoctrinePlugin_doctrine_lib_path', sfConfig::get('sf_lib_dir') . '/vendor/doctrine/Doctrine.php');
}

Patch Symfony Library

Now you need to patch the Symfony library with the back-ported changes related to Doctrine from the Symfony 1.3 branch. This patch is very simple, and currently only effects one file.

Navigate to your Symfony lib directory. Depending on how you started your project, this is probably the lib/symfony directory in your project.

$ wget http://www.bltweb.net/patches/symfony-1.2.7-doctrine-1.1.patch
$ patch -p0 < symfony-1.2.7-doctrine-1.1.patch

Now rebuild your model forms. From your project’s root directory:

$ php symfony doctrine:build-forms
$ php symfony cc

Patch sfDoctrineGuardPlugin

If you use the sfDoctrineGuardPlugin you will need to apply another patch.

From your project’s root directory:

$ wget http://www.bltweb.net/patches/sfDoctrineGuardPlugin-doctrine-1.1.patch
$ patch -p0 < sfDoctrineGuardPlugin-doctrine-1.1.patch

Finished!

You should now be able to use Doctrine 1.1 with Symfony 1.2. I haven’t run into any problems using it, however I’ve just gotten started with my new project and haven’t done much of anything yet! If you have troubles let me know.

For anyone on Gentoo, I have a symfony ebuild in my Gentoo Overlay that will install Symfony 1.2 with Doctrine 1.1 support for you.

I’ll try to keep this post updated if I come across anything else that needs to change when using Doctrine 1.1 with Symfony 1.2.

Web Applications ,

  1. June 1st, 2009 at 04:25 | #1

    Helpful. Thanks.

  2. June 2nd, 2009 at 08:01 | #2

    Brandon – genious. We upgraded to Doctrine 1.1 yesterday on a huge project and ran into problems all of the place (specifically the problem with DoctrineGuard and the relationship saving problem in the generated forms).

    You’ve given new life to our use of Doctrine 1.1 with Symfony 1.2.

    Are you tracking any other patches related to Doctrine 1.1 in Symfony 1.3 going forward or is it your feeling that the above patches represent nearly all the necessary fixes?

  3. June 2nd, 2009 at 08:39 | #3

    @Ryan Weaver
    I’ve been watching the Symfony issues and commits and haven’t seen anything new. If I do I plan on updating this page and posting a comment.

    Unfortunately, I had to put my new project on hold for a few weeks so I haven’t had much opportunity to test for more bugs. Reading through the Doctrine 1.1 changelog, I don’t anticipate anything big – not to mention the Symfony devs are currently working with Doctrine 1.1 in the Symfony 1.3 codebase.

  4. June 16th, 2009 at 04:59 | #4

    Thank you, this is really great. I can’t wait Symfony 1.3 to use Doctrine 1.1.

  5. June 30th, 2009 at 17:07 | #5

    Hi guys,

    THe roadmap is that Symfony 1.3 will use Doctrine 1.2, and not Doctrine 1.1… =) Just crosses fingers!

    We just have a lot of work to do and very small time. If everything goes okay, we’ll launch 1.2 before sf 1.3 and they’ll move externals to new version.

    Cheers,

    Guilherme Blanco

  6. July 1st, 2009 at 00:02 | #6

    Guilherme – I’m pulling for you guys with version 1.2. I love Doctrine but hate that I can’t use the latest version of Doctrine with the latest version of Symfony (at least not without some core modifications). We’re getting hurt a little bit by multiple databases in Doctrine 1.0 – I’d love to increase all the way to Doctrine 1.2 with Symfony 1.3.

    Anyways, thanks and good luck!

  7. July 1st, 2009 at 08:20 | #7

    Agreed. You guys are doing an awesome job with Doctrine. I’m looking forward to the next release of Symfony and Doctrine!

  8. August 14th, 2009 at 02:49 | #8

    I am working on a Fedora RPM for Symfony. This seems to mean that I will have to do a Doctrine 1.1 RPM too and this means that I will have to use your package.

    I will report how it goes :-)

  9. Chtipepere
    August 21st, 2009 at 12:19 | #9

    Hi,

    I’ve applied your patches, it seems better, but I still can’t create new group nor permission, always get :
    The item has not been saved due to some errors.
    I’ve also applied the second patch given here http://trac.symfony-project.org/ticket/6373 but I’m still stuck with this problem…
    If you have any idea, it will be greatful.
    (Symfony 1.2.9DEV + Doctrine 1.1 + sfDoctrineGuardPlugin)
    Regards

  10. Chtipepere
    August 21st, 2009 at 12:20 | #10

    Chtipepere :
    Hi,
    I’ve applied your patches, it seems better, but I still can’t create new group nor permission, always get :
    The item has not been saved due to some errors.
    I’ve also applied the second patch given here http://trac.symfony-project.org/ticket/6373 but I’m still stuck with this problem…
    If you have any idea, it will be greatful.
    (Symfony 1.2.9DEV + Doctrine 1.1 + sfDoctrineGuardPlugin)
    Regards

    I’ve forgot : I can set permission or a group to a user…

  11. September 25th, 2009 at 01:11 | #11

    I’ve read you detailed observations and applied the patches.
    I still always get “The item has not been saved due to some errors.” when I try to save any of the sfDoctrineGuard forms.
    I’m using sf 1.2.8 and doctrine 1.1
    Any ideas?

  12. September 25th, 2009 at 08:59 | #12

    @Alex
    I stopped using the sfDoctrineGuard plugin so I’m not sure. You might want to try the patch at http://trac.symfony-project.org/ticket/6373. Sorry I am not more help :(

  13. July 5th, 2010 at 05:43 | #13

    Nice one… did not know that. thx

  14. July 6th, 2010 at 07:04 | #14

    Mariano

  15. December 12th, 2011 at 20:33 | #15

    Hi,the context is so helpful,3Q,but symfony 1.1 does not support doctrine,whether i need to install the doctrine by downloading??? Thanks!

  16. May 3rd, 2015 at 22:30 | #16

    征服服务端传说45服务端天之炼狱服务端天堂II服务端墨香服务端
    天堂I私服开服挑战OL私服开服剑侠情缘私服开服奇侠XIAH私服开服挑战私服开服
    风云雄霸天下开区一条龙天之炼狱一条龙大话西游开区一条龙精灵复兴开区一条龙
    魔域私服一条龙开区服务 http://www.m9yx.com/

  1. December 2nd, 2009 at 22:19 | #1