. */ namespace Doctrine\ORM\Persisters; use Doctrine\ORM\PersistentCollection; /** * Persister for many-to-many collections. * * @author Roman Borschel * @since 2.0 */ class ManyToManyPersister extends AbstractCollectionPersister { /** * {@inheritdoc} * * @override */ protected function _getDeleteRowSql(PersistentCollection $coll) { $mapping = $coll->getMapping(); $joinTable = $mapping->getJoinTable(); $columns = $mapping->getJoinTableColumnNames(); return 'DELETE FROM ' . $joinTable['name'] . ' WHERE ' . implode(' = ? AND ', $columns) . ' = ?'; } /** * {@inheritdoc} * * @override */ protected function _getDeleteRowSqlParameters(PersistentCollection $coll, $element) { $params = array_merge( $this->_uow->getEntityIdentifier($coll->getOwner()), $this->_uow->getEntityIdentifier($element) ); //var_dump($params); return $params; } /** * {@inheritdoc} * * @override */ protected function _getUpdateRowSql(PersistentCollection $coll) {} /** * {@inheritdoc} * * @override */ protected function _getInsertRowSql(PersistentCollection $coll) { $mapping = $coll->getMapping(); $joinTable = $mapping->getJoinTable(); $columns = $mapping->getJoinTableColumnNames(); return 'INSERT INTO ' . $joinTable['name'] . ' (' . implode(', ', $columns) . ')' . ' VALUES (' . implode(', ', array_fill(0, count($columns), '?')) . ')'; } /** * {@inheritdoc} * * @override */ protected function _getInsertRowSqlParameters(PersistentCollection $coll, $element) { // FIXME: This is still problematic for composite keys because we silently // rely on a specific ordering of the columns. $params = array_merge( $this->_uow->getEntityIdentifier($coll->getOwner()), $this->_uow->getEntityIdentifier($element) ); //var_dump($params); return $params; } /** * {@inheritdoc} * * @override */ protected function _getDeleteSql(PersistentCollection $coll) { $mapping = $coll->getMapping(); $joinTable = $mapping->getJoinTable(); $whereClause = ''; foreach ($mapping->sourceToRelationKeyColumns as $relationColumn) { if ($whereClause !== '') $whereClause .= ' AND '; $whereClause .= "$relationColumn = ?"; } return 'DELETE FROM ' . $joinTable['name'] . ' WHERE ' . $whereClause; } /** * {@inheritdoc} * * @override */ protected function _getDeleteSqlParameters(PersistentCollection $coll) { //FIXME: This is still problematic for composite keys because we silently // rely on a specific ordering of the columns. return $this->_uow->getEntityIdentifier($coll->getOwner()); } }