From 1350eaea412edee09059c7a34ceb5d9a47975f57 Mon Sep 17 00:00:00 2001 From: zYne Date: Tue, 31 Jul 2007 19:47:17 +0000 Subject: [PATCH] --- .../docs/en/dql-doctrine-query-language.txt | 3 +- .../from-clause.txt | 8 --- .../join-syntax.txt | 63 +++++++++++++++++++ 3 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 manual/new/docs/en/dql-doctrine-query-language/join-syntax.txt diff --git a/manual/new/docs/en/dql-doctrine-query-language.txt b/manual/new/docs/en/dql-doctrine-query-language.txt index db5bae935..55f66f8c7 100644 --- a/manual/new/docs/en/dql-doctrine-query-language.txt +++ b/manual/new/docs/en/dql-doctrine-query-language.txt @@ -3,6 +3,7 @@ ++ UPDATE queries ++ DELETE queries ++ FROM clause +++ JOIN syntax ++ WHERE clause ++ Conditional expressions ++ Functional Expressions @@ -11,4 +12,4 @@ ++ ORDER BY clause ++ LIMIT and OFFSET clauses ++ Examples -++ BNF +++ BNF diff --git a/manual/new/docs/en/dql-doctrine-query-language/from-clause.txt b/manual/new/docs/en/dql-doctrine-query-language/from-clause.txt index 2acdb7da0..216850406 100644 --- a/manual/new/docs/en/dql-doctrine-query-language/from-clause.txt +++ b/manual/new/docs/en/dql-doctrine-query-language/from-clause.txt @@ -8,14 +8,6 @@ The {{FROM}} clause indicates the component or components from which to retrieve * The default join type is {{LEFT JOIN}}. This join can be indicated by the use of either {{LEFT JOIN}} clause or simply '{{,}}', hence the following queries are equal: - -SELECT u.*, p.* FROM User u LEFT JOIN u.Phonenumber -SELECT u.*, p.* FROM User u, u.Phonenumber p - -* {{INNER JOIN}} produces an intersection between two specified components (that is, each and every record in the first component is joined to each and every record in the second component). So basically {{INNER JOIN}} can be used when you want to efficiently fetch for example all users which have one or more phonenumbers. - -SELECT u.*, p.* FROM User u INNER JOIN u.Phonenumber p - diff --git a/manual/new/docs/en/dql-doctrine-query-language/join-syntax.txt b/manual/new/docs/en/dql-doctrine-query-language/join-syntax.txt new file mode 100644 index 000000000..177cfe267 --- /dev/null +++ b/manual/new/docs/en/dql-doctrine-query-language/join-syntax.txt @@ -0,0 +1,63 @@ +Syntax: + + +[[LEFT | INNER] JOIN ] [ON | WITH] , +[[LEFT | INNER] JOIN ] [ON | WITH] , +... +[[LEFT | INNER] JOIN ] [ON | WITH] + + +DQL supports two kinds of joins INNER JOINs and LEFT JOINs. For each joined component, you can optionally specify an alias. + +* The default join type is {{LEFT JOIN}}. This join can be indicated by the use of either {{LEFT JOIN}} clause or simply '{{,}}', hence the following queries are equal: + + +SELECT u.*, p.* FROM User u LEFT JOIN u.Phonenumber + +SELECT u.*, p.* FROM User u, u.Phonenumber p + + +The recommended form is the first one. + +* {{INNER JOIN}} produces an intersection between two specified components (that is, each and every record in the first component is joined to each and every record in the second component). So basically {{INNER JOIN}} can be used when you want to efficiently fetch for example all users which have one or more phonenumbers. + + +SELECT u.*, p.* FROM User u INNER JOIN u.Phonenumber p + + +By default DQL auto-adds the primary key join condition, so for DQL query: + + +SELECT u.id, p.id FROM User u LEFT JOIN u.Phonenumber + + +Would have a SQL equivalent: + + +SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id = p.user_id + + +If you want to override this behaviour and add your own custom join condition you can do it with the {{ON}} keyword. Consider the following DQL query: + + +SELECT u.id, p.id FROM User u LEFT JOIN u.Phonenumber ON u.id = 2 + + +This query would be converted into SQL: + + +SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id = 2 + + +Most of the time you don't need to override the primary join condition, rather you may want to add some custom conditions. This can be achieved with the {{WITH}} keyword. + +DQL: + +SELECT u.id, p.id FROM User u LEFT JOIN u.Phonenumber WITH u.id = 2 + + +SQL: + +SELECT u.id AS u__id, p.id AS p__id FROM User u LEFT JOIN Phonenumber p ON u.id = p.user_id AND u.id = 2 + +