Commit abb56d4f authored by zYne's avatar zYne

Docs updated

parent 99e81586
...@@ -18,7 +18,7 @@ $coll = $q->select('u.name, u.age, e.address') ...@@ -18,7 +18,7 @@ $coll = $q->select('u.name, u.age, e.address')
// find all users, user email and user phonenumbers // find all users, user email and user phonenumbers
$coll = $q->from('FROM User u') $coll = $q->from('FROM User u')
->leftJoin('u.Email e') ->innerJoin('u.Email e')
->leftJoin('u.Phonenumber p') ->innerJoin('u.Phonenumber p')
->execute(); ->execute();
?> ?>
...@@ -5,4 +5,8 @@ $q = new Doctrine_Query(); ...@@ -5,4 +5,8 @@ $q = new Doctrine_Query();
// initalizing a new Doctrine_Query (using custom connection parameter) // initalizing a new Doctrine_Query (using custom connection parameter)
// here $conn is an instance of Doctrine_Connection // here $conn is an instance of Doctrine_Connection
$q = new Doctrine_Query($conn); $q = new Doctrine_Query($conn);
// an example using the create method
// here we simple fetch all users
$users = Doctrine_Query::create()->from('User')->execute();
?> ?>
<?php <?php
$q = new Doctrine_Query();
// find all users, sort by name descending // find all users, sort by name descending
$coll = $conn->query("FROM User ORDER BY User.name DESC"); $users = $q->from('User u')->orderby('u.name DESC');
// find all users sort by name ascending // find all users sort by name ascending
$coll = $conn->query("FROM User ORDER BY User.name ASC"); $users = $q->from('User u')->orderby('u.name ASC');
// or
$coll = $conn->query("FROM User ORDER BY User.name");
// find all users and their emails, sort by email address // find all users and their emails, sort by email address in ascending order
$coll = $conn->query("FROM User, User.Email ORDER BY User.Email.address"); $users = $q->from('User u')->leftJoin('u.Email e')->orderby('e.address');
// find all users and their emails, sort by user name and email address // find all users and their emails, sort by user name and email address
$coll = $conn->query("FROM User, User.Email ORDER BY User.name, User.Email.address"); $users = $q->from('User u')->leftJoin('u.Email e')
->addOrderby('u.name')->addOrderby('e.address');
?> ?>
<?php <?php
/**
$str = " $str = "
The following examples should give a hint of how DQL is converted into SQL. The following examples should give a hint of how DQL is converted into SQL.
The classes used in here are the same as in chapter 14.1 (Users and groups are both entities etc). The classes used in here are the same as in chapter 14.1 (Users and groups are both entities etc).
...@@ -52,4 +53,5 @@ foreach($e as $line) { ...@@ -52,4 +53,5 @@ foreach($e as $line) {
} }
} }
renderQueries($str); renderQueries($str);
*/
?> ?>
...@@ -3,7 +3,7 @@ The FROM clause indicates the component or components from which to retrieve rec ...@@ -3,7 +3,7 @@ The FROM clause indicates the component or components from which to retrieve rec
If you name more than one component, you are performing a join. If you name more than one component, you are performing a join.
For each table specified, you can optionally specify an alias. Doctrine_Query offers easy to use For each table specified, you can optionally specify an alias. Doctrine_Query offers easy to use
methods such as from(), addFrom(), leftJoin() and innerJoin() for managing the FROM part of your DQL query. methods such as from(), addFrom(), leftJoin() and innerJoin() for managing the FROM part of your DQL query.
<br \><br \>
<?php <?php
renderCode("<?php renderCode("<?php
// find all users // find all users
...@@ -15,4 +15,5 @@ renderCode("<?php ...@@ -15,4 +15,5 @@ renderCode("<?php
\$coll = \$q->select('u.name')->('User u'); \$coll = \$q->select('u.name')->('User u');
?>"); ?>");
?> ?> <br \><br \>
The following example shows how to use leftJoin and innerJoin methods: <br \><br \>
<?php ?>
DQL (Doctrine Query Language) is a object query language which allows DQL (Doctrine Query Language) is a object query language which allows
you to find objects. DQL understands things like object relationships, polymorphism and you to find objects. DQL understands things like object relationships, polymorphism and
inheritance (including column aggregation inheritance). inheritance (including column aggregation inheritance).
For more info about DQL see the actual DQL chapter.
<br \><br \> <br \><br \>
So instead of writing lots of SQL inner and outer joins, unions and subselects yourself, Doctrine_Query along with Doctrine_Expression provide an easy-to-use wrapper for writing DQL queries. Creating a new
you can write simple DQL queries where relationships are being referenced with dot-notation. query object can be done by either using the new operator or by calling create method. The create method exists for allowing easy
<br \><br \> method call chaining.
You can execute DQL queries with Doctrine_Connection::query() method.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment