1<?php
2/*
3 *  $Id$
4 *
5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 *
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the LGPL. For more information, see
19 * <http://www.doctrine-project.org>.
20 */
21
22/**
23 * Doctrine_Ticket_1467_TestCase
24 *
25 * @package     Doctrine
26 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
27 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28 * @category    Object Relational Mapping
29 * @link        www.doctrine-project.org
30 * @since       1.0
31 * @version     $Revision$
32 */
33class Doctrine_Ticket_1467_TestCase extends Doctrine_UnitTestCase
34{
35    public function testTicket()
36    {
37        // SELECT picture_id FROM ItemPicture INNER JOIN Puzzle ON ItemPicture.item_id=ItemPuzzle_item_id
38        $q = Doctrine_Query::create()
39            ->select('pic.id')
40            ->from('T1467_Picture pic')
41            ->innerJoin('pic.Items ite')
42            ->innerJoin('ite.Puzzles puz');
43
44        $this->assertEqual($q->getDql(), 'SELECT pic.id FROM T1467_Picture pic INNER JOIN pic.Items ite INNER JOIN ite.Puzzles puz');
45        $this->assertEqual($q->getSqlQuery(), 'SELECT t.id AS t__id FROM t1467__picture t INNER JOIN t1467__item_picture t3 ON (t.id = t3.picture_id) INNER JOIN t1467__item t2 ON t2.id = t3.item_id INNER JOIN t1467__item_puzzle t5 ON (t2.id = t5.item_id) INNER JOIN t1467__puzzle t4 ON t4.id = t5.puzzle_id');
46    }
47}
48
49
50class T1467_Item extends Doctrine_Record
51{
52    public function setTableDefinition()
53    {
54        $this->hasColumn('name', 'string', 50);
55    }
56
57    public function setUp()
58    {
59        $this->hasMany('T1467_Picture as Pictures', array(
60            'refClass' => 'T1467_ItemPicture',
61            'local' => 'item_id',
62            'foreign' => 'picture_id'
63        ));
64
65        $this->hasMany('T1467_Puzzle as Puzzles', array(
66            'refClass' => 'T1467_ItemPuzzle',
67            'local' => 'item_id',
68            'foreign' => 'puzzle_id'
69        ));
70    }
71}
72
73
74class T1467_Picture extends Doctrine_Record
75{
76    public function setTableDefinition()
77    {
78        $this->hasColumn('name', 'string', 50);
79    }
80
81    public function setUp()
82    {
83        $this->hasMany('T1467_Item as Items', array(
84            'refClass' => 'T1467_ItemPicture',
85            'local' => 'picture_id',
86            'foreign' => 'item_id'
87        ));
88    }
89}
90
91
92class T1467_Puzzle extends Doctrine_Record
93{
94    public function setTableDefinition()
95    {
96        $this->hasColumn('name', 'string', 50);
97    }
98
99    public function setUp()
100    {
101        $this->hasMany('T1467_Item as Items', array(
102            'refClass' => 'T1467_ItemPicture',
103            'local' => 'puzzle_id',
104            'foreign' => 'item_id'
105        ));
106    }
107}
108
109
110class T1467_ItemPicture extends Doctrine_Record
111{
112    public function setTableDefinition()
113    {
114        $this->hasColumn('item_id', 'integer', null, array('primary' => true));
115        $this->hasColumn('picture_id', 'integer', null, array('primary' => true));
116    }
117}
118
119
120class T1467_ItemPuzzle extends Doctrine_Record
121{
122    public function setTableDefinition()
123    {
124        $this->hasColumn('item_id', 'integer', null, array('primary' => true));
125        $this->hasColumn('puzzle_id', 'integer', null, array('primary' => true));
126    }
127}