I have recently started to learn using of Doctrine 2.0 framework for PHP. Now I have already managed to utilize some Doctrine things (using MySQL), insert some data using defined XML model, but now I have a problem with selecting data. Everywhere, including Doctrine site, I have found that data are being selected by DQL or raw SQL. But in this way, I lose half of advantages that ORM gives. How can I select data using pure ORM, for example like I can do with Hibernate in Java?
Here is some mapping XML example from the Doctrine site I am working with:
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Product" table="products">
<id name="id" type="integer" column="product_id">
<generator strategy="AUTO" />
</id>
<field name="name" column="product_name" type="string" />
</entity>
</doctrine-mapping>
In the beginning I missed that one too, but what is important to understand is that DQL doesn’t understand concept of tables (read note DQL is not SQL) it is purely object-oriented query. That is you query your models, not the database directly.
Manual itself states that DQL “is very similar to the Hibernate Query Language“.