$this->definition['type'] == IPF_ORM_Relation::ONE_COMPOSITE);
}
- public function getRelationDql($count)
- {
- $component = $this->getTable()->getComponentName();
-
- $dql = 'FROM ' . $component
- . ' WHERE ' . $component . '.' . $this->definition['foreign']
- . ' IN (' . substr(str_repeat('?, ', $count), 0, -2) . ')';
-
- return $dql;
- }
+ abstract public function getRelationDql($count, $context);
abstract public function fetchRelatedFor(IPF_ORM_Record $record);
return $this->definition['refTable'];
}
- public function getRelationDql($count, $context = 'record')
+ public function getRelationDql($count, $context)
{
- $table = $this->definition['refTable'];
$component = $this->definition['refTable']->getComponentName();
+ $thisTable = $this->getTable()->getComponentName();
+ $sub = substr(str_repeat('?, ', $count), 0, -2);
switch ($context) {
case "record":
- $sub = substr(str_repeat("?, ", $count),0,-2);
- $dql = 'FROM ' . $this->getTable()->getComponentName();
- $dql .= '.' . $component;
- $dql .= ' WHERE ' . $this->getTable()->getComponentName()
- . '.' . $component . '.' . $this->definition['local'] . ' IN (' . $sub . ')';
+ $dql = 'FROM ' . $thisTable . '.' . $component .
+ ' WHERE ' . $thisTable . '.' . $component . '.' . $this->definition['local'] . ' IN (' . $sub . ')';
break;
case "collection":
- $sub = substr(str_repeat("?, ", $count),0,-2);
- $dql = 'FROM ' . $component . '.' . $this->getTable()->getComponentName();
- $dql .= ' WHERE ' . $component . '.' . $this->definition['local'] . ' IN (' . $sub . ')';
+ $dql = 'FROM ' . $component . '.' . $thisTable .
+ ' WHERE ' . $component . '.' . $this->definition['local'] . ' IN (' . $sub . ')';
break;
}
return $dql;
if (empty($id) || ! $this->definition['table']->getAttribute(IPF_ORM::ATTR_LOAD_REFERENCES)) {
$coll = new IPF_ORM_Collection($this->getTable());
} else {
- $coll = $this->getTable()->getConnection()->query($this->getRelationDql(1), array($id));
+ $coll = $this->getTable()->getConnection()->query($this->getRelationDql(1, 'record'), array($id));
}
$coll->setReference($record, $this);
return $coll;
}
-}
\ No newline at end of file
+}
+
$related = new IPF_ORM_Collection($this->getTable());
} else {
- $query = $this->getRelationDql(1);
+ $query = $this->getRelationDql(1, '');
$related = $this->getTable()->getConnection()->query($query, $id);
}
$related->setReference($record, $this);
return $related;
}
+ public function getRelationDql($count, $context)
+ {
+ $table = $this->getTable();
+ $component = $table->getComponentName();
+
+ $dql = 'FROM ' . $component
+ . ' WHERE ' . $component . '.' . $this->definition['foreign']
+ . ' IN (' . substr(str_repeat('?, ', $count), 0, -2) . ')';
+
+ return $dql;
+ }
+
public function getCondition($alias = null)
{
if ( ! $alias) {
return $related;
}
+ public function getRelationDql($count, $context)
+ {
+ $component = $this->getTable()->getComponentName();
+ return 'FROM ' . $component .
+ ' WHERE ' . $component . '.' . $this->definition['foreign'] .
+ ' IN (' . substr(str_repeat('?, ', $count), 0, -2) . ')';
+ }
+
public function getCondition($alias = null)
{
if ( ! $alias) {