News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

ServerGrove Blog:
Enforcing unique key constrains with Doctrine ODM for MongoDB & Symfony 2
October 21, 2010 @ 11:58:22

New on the ServerGrove blog today is a quick post talking about how you can enforce key constraints on a MongoDb with Doctrine in Symfony.

Of course you can define unique indexes to prevent duplicate values and there are a couple of different syntax options to do so, which are clearly defined in the official documentation. But defining and creating the indexes is not enough. You must specify when you want to enforce the constrain, this is due to the fact that the PHP driver needs to tell MongoDB to throw an error when a duplicate key is found.

The fix is as simple as adding a "safe" option to the "flush()" call on your database object. If you give it a value of "true", the ORM is smart enough to handle things on its own.

0 comments voice your opinion now!
mongodb enforce symfony constraint unique doctrine


blog comments powered by Disqus

Similar Posts

Ade Slade's Blog: Integrating Zend Framework 1 and Pimple

Mike Naberezny's Blog: Symfony Templates and Ruby's ERb

Richard Miller's Blog: Symfony2: Moving Away From the Base Controller

Hannes Magnusson: Query logging and profiling in MongoDB

Matthias Noback: Unnecessary contrapositions in the new "Symfony Best Practices"


Community Events

Don't see your event here?
Let us know!


introduction api podcast community conference development laravel5 release interview series library voicesoftheelephpant laravel psr7 framework opinion language extension unittest wordpress

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework