jblue
jblue

Reputation: 4450

Is ORM all or nothing?

If I use an ORM let's say with Zend or Symfony. Is it an all or nothing deal?

I'd like to use the ORM, but also want to optimize performance in some cases and write the query myself to get to the nitty gritty. So if I start using an ORM, is it going to be difficult to do it the old way once I include it in my project?

Upvotes: 8

Views: 462

Answers (3)

Mike Graf
Mike Graf

Reputation: 5307

You can mix and match all you like. The main risk is introducing incompatible inconsistencies between your tools. Hypothetical Ex:

if I have a doctrine2 ORM entity called a User and I use Zend_Db_Table to change some values between flushes on the users table, I may have some inadvertent side effects or undesired behaviour.

Upvotes: 0

Jeremy Kauffman
Jeremy Kauffman

Reputation: 10403

Using Doctrine it is fairly easy to "break out" of the ORM. Doctrine lets you write queries in 4 different ways:

  • DQL. Doctrine's own query language that comes with all of the benefits of Doctrine.
  • "raw" DQL ("Native queries" in Doctrine2). This is similar to DQL but allows a little more flexibility in commands (e.g. database specific features). In this mode, you'll have to specify a little more about how components are related to one another.
  • SQL, using PHP's PDO. You can use a Doctrine_Connection to get a PDO instance which lets you write queries but still have the added safety and ease of use granted by PDO.
  • raw SQL. While I'm not sure why you'd want it, I think Doctrine provides this, if not, you could always break out of Doctrine entirely.

If you're using Doctrine inside of Symfony, there are absolutely no features of Symfony that lock you into using Doctrine, even if it's enabled.

One final warning: if you're using some of Doctrine's advanced features (e.g. events or behaviors) these will become difficult to tie in when you do queries outside of DQL.

Upvotes: 6

p.campbell
p.campbell

Reputation: 100557

Most ORMs will let you run adhoc queries.

Upvotes: 9

Related Questions