Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 671
jblue Avatar asked Sep 22 '10 01:09

jblue


People also ask

Is ORM really necessary?

Using an ORM does not mean that you do not have to care anymore about how the application interacts with the database so you can treat it as a neglectable piece in your architecture. On the contrary, you just added another layer of abstraction and complexity, the ORM itself.

What is not ORM?

NotORM is a PHP library for simple working with data in the database. The most interesting feature is a very easy work with table relationships. The overall performance is also very important and NotORM can actually run faster than a native driver. NotORM for databases is like SimpleXML for XML documents.

What is the purpose of an ORM?

What is an ORM? An object-relational mapper provides an object-oriented layer between relational databases and object-oriented programming languages without having to write SQL queries. It standardizes interfaces reducing boilerplate and speeding development time.

Is it better to use ORM or SQL?

When it comes to hands-on management, SQL is higher than ORM. It is because of the human expertise involved in running queries in data management and retrieval. It is important to know how to use SQL in order to maximize the benefits and performance of the database.


2 Answers

Most ORMs will let you run adhoc queries.

  • Doctrine has 'doctrine2 native queries'
  • Propel with 'raw SQL queries'
like image 87
p.campbell Avatar answered Oct 06 '22 03:10

p.campbell


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.

like image 27
Jeremy Kauffman Avatar answered Oct 06 '22 02:10

Jeremy Kauffman