/** * @param ObjectBuilder $builder * @return string */ protected function addObjectCompute(ObjectBuilder $builder) { $conditions = array(); if ($this->getParameter('condition')) { $conditions[] = $this->getParameter('condition'); } $bindings = array(); $database = $this->getTable()->getDatabase(); if ($this->getForeignKey()->isPolymorphic()) { throw new \InvalidArgumentException('AggregateColumnBehavior does not work with polymorphic relations.'); } foreach ($this->getForeignKey()->getMapping() as $index => $mapping) { list($localColumn, $foreignColumn) = $mapping; $conditions[] = $localColumn->getFullyQualifiedName() . ' = :p' . ($index + 1); $bindings[$index + 1] = $foreignColumn->getPhpName(); } $tableName = $database->getTablePrefix() . $this->getParameter('foreign_table'); if ($database->getPlatform()->supportsSchemas() && $this->getParameter('foreign_schema')) { $tableName = $this->getParameter('foreign_schema') . $database->getPlatform()->getSchemaDelimiter() . $tableName; } $sql = sprintf('SELECT %s FROM %s WHERE %s', $this->getParameter('expression'), $builder->getTable()->quoteIdentifier($tableName), implode(' AND ', $conditions)); return $this->renderTemplate('objectCompute', array('column' => $this->getColumn(), 'sql' => $sql, 'bindings' => $bindings)); }
/** * @param ObjectBuilder $builder * @return string */ protected function addObjectCompute(ObjectBuilder $builder) { $conditions = array(); if ($this->getParameter('condition')) { $conditions[] = $this->getParameter('condition'); } $bindings = array(); $database = $this->getTable()->getDatabase(); foreach ($this->getForeignKey()->getColumnObjectsMapping() as $index => $columnReference) { $conditions[] = $columnReference['local']->getFullyQualifiedName() . ' = :p' . ($index + 1); $bindings[$index + 1] = $columnReference['foreign']->getPhpName(); } $tableName = $database->getTablePrefix() . $this->getParameter('foreign_table'); if ($database->getPlatform()->supportsSchemas() && $this->getParameter('foreign_schema')) { $tableName = $this->getParameter('foreign_schema') . $database->getPlatform()->getSchemaDelimiter() . $tableName; } $sql = sprintf('SELECT %s FROM %s WHERE %s', $this->getParameter('expression'), $builder->getTable()->quoteIdentifier($tableName), implode(' AND ', $conditions)); return $this->renderTemplate('objectCompute', array('column' => $this->getColumn(), 'sql' => $sql, 'bindings' => $bindings)); }