3
* $Id: Self.php 1434 2007-05-22 15:57:17Z zYne $
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.
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.phpdoctrine.org>.
23
* Doctrine_Relation_Association_Self
26
* @subpackage Relation
27
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
28
* @link www.phpdoctrine.org
30
* @version $Revision: 1434 $
31
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
33
class Doctrine_Relation_Nest extends Doctrine_Relation_Association
38
* @param integer $count
41
/*public function getRelationDql($count, $context = 'record')
45
$identifierColumnNames = $this->definition['table']->getIdentifierColumnNames();
46
$identifier = array_pop($identifierColumnNames);
47
$sub = 'SELECT '.$this->definition['foreign']
48
. ' FROM '.$this->definition['refTable']->getTableName()
49
. ' WHERE '.$this->definition['local']
52
$sub2 = 'SELECT '.$this->definition['local']
53
. ' FROM '.$this->definition['refTable']->getTableName()
54
. ' WHERE '.$this->definition['foreign']
57
$dql = 'FROM ' . $this->definition['table']->getComponentName()
58
. '.' . $this->definition['refTable']->getComponentName()
59
. ' WHERE ' . $this->definition['table']->getComponentName()
61
. ' IN (' . $sub . ')'
62
. ' || ' . $this->definition['table']->getComponentName()
64
. ' IN (' . $sub2 . ')';
67
$sub = substr(str_repeat('?, ', $count),0,-2);
68
$dql = 'FROM '.$this->definition['refTable']->getComponentName()
69
. '.' . $this->definition['table']->getComponentName()
70
. ' WHERE '.$this->definition['refTable']->getComponentName()
71
. '.' . $this->definition['local'] . ' IN (' . $sub . ')';
77
public function fetchRelatedFor(Doctrine_Record $record)
79
$id = $record->getIncremented();
81
if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) {
82
return new Doctrine_Collection($this->getTable());
84
$q = new Doctrine_RawSql($this->getTable()->getConnection());
86
$assocTable = $this->getAssociationFactory()->getTableName();
87
$tableName = $record->getTable()->getTableName();
88
$identifierColumnNames = $record->getTable()->getIdentifierColumnNames();
89
$identifier = array_pop($identifierColumnNames);
91
$sub = 'SELECT ' . $this->getForeignRefColumnName()
92
. ' FROM ' . $assocTable
93
. ' WHERE ' . $this->getLocalRefColumnName()
96
$condition[] = $tableName . '.' . $identifier . ' IN (' . $sub . ')';
97
$joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getForeignRefColumnName();
99
if ($this->definition['equal']) {
100
$sub2 = 'SELECT ' . $this->getLocalRefColumnName()
101
. ' FROM ' . $assocTable
102
. ' WHERE ' . $this->getForeignRefColumnName()
105
$condition[] = $tableName . '.' . $identifier . ' IN (' . $sub2 . ')';
106
$joinCondition[] = $tableName . '.' . $identifier . ' = ' . $assocTable . '.' . $this->getLocalRefColumnName();
108
$q->select('{'.$tableName.'.*}, {'.$assocTable.'.*}')
109
->from($tableName . ' INNER JOIN ' . $assocTable . ' ON ' . implode(' OR ', $joinCondition))
110
->where(implode(' OR ', $condition));
111
$q->addComponent($tableName, $this->getClass());
113
$path = $this->getClass(). '.' . $this->getAssociationFactory()->getComponentName();
114
if ($this->definition['refClassRelationAlias']) {
115
$path = $this->getClass(). '.' . $this->definition['refClassRelationAlias'];
117
$q->addComponent($assocTable, $path);
119
$params = ($this->definition['equal']) ? array($id, $id) : array($id);
120
$res = $q->execute($params);
b'\\ No newline at end of file'