2

I have two entities with one-to-many relation using annotation in my DQL Query. What is the difference between those two queries?

1-

SELECT p, c FROM AcmeStoreBundle:Product p
    JOIN p.category c
WHERE p.id = :id

2-

SELECT p, c FROM AcmeStoreBundle:Product p
    JOIN AcmeStoreBundle:Category c
        ON p.categoryid = c.id
WHERE p.id = :id

When I check the benchmark I found the second approach take less time. Can someone list the pros and cons for each way and when each one is useful?

A.L
  • 10,259
  • 10
  • 67
  • 98
SMSM
  • 1,509
  • 3
  • 19
  • 34
  • Can you please give the result of the benchmark? You can compare the resulting queries by [displaying them](http://stackoverflow.com/a/11379563/2257664). – A.L Mar 11 '14 at 01:01

1 Answers1

1

According to official documentation you cannot execute the second query. I haven't actually tried it but you say it's possible? If so, I believe, it's bad practice to express relations in such manner...

Every ORM is object oriented, and such emphasizes the need for objects rather than ids. Your second query look more like a native query of relational database where JOIN works with ids.

Jovan Perovic
  • 19,846
  • 5
  • 44
  • 85