Added support for unlink all
This commit is contained in:
parent
c8578d434a
commit
404338f46f
@ -1456,12 +1456,13 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
|||||||
/**
|
/**
|
||||||
* removeLinks
|
* removeLinks
|
||||||
* removes links from this record to given records
|
* removes links from this record to given records
|
||||||
|
* if no ids are given, it removes all links
|
||||||
*
|
*
|
||||||
* @param string $alias related component alias
|
* @param string $alias related component alias
|
||||||
* @param array $ids the identifiers of the related records
|
* @param array $ids the identifiers of the related records
|
||||||
* @return Doctrine_Record this object
|
* @return Doctrine_Record this object
|
||||||
*/
|
*/
|
||||||
public function unlink($alias, $ids)
|
public function unlink($alias, $ids = array())
|
||||||
{
|
{
|
||||||
$ids = (array) $ids;
|
$ids = (array) $ids;
|
||||||
|
|
||||||
@ -1472,8 +1473,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
|||||||
if ($rel instanceof Doctrine_Relation_Association) {
|
if ($rel instanceof Doctrine_Relation_Association) {
|
||||||
$q->delete()
|
$q->delete()
|
||||||
->from($rel->getAssociationTable()->getComponentName())
|
->from($rel->getAssociationTable()->getComponentName())
|
||||||
->where($rel->getLocal() . ' = ?', array_values($this->identifier()))
|
->where($rel->getLocal() . ' = ?', array_values($this->identifier()));
|
||||||
->whereIn($rel->getForeign(), $ids);
|
|
||||||
|
if (count($ids) > 0) {
|
||||||
|
$q->whereIn($rel->getForeign(), $ids);
|
||||||
|
}
|
||||||
|
|
||||||
$q->execute();
|
$q->execute();
|
||||||
|
|
||||||
@ -1481,8 +1485,11 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
|||||||
} elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
|
} elseif ($rel instanceof Doctrine_Relation_ForeignKey) {
|
||||||
$q->update($rel->getTable()->getComponentName())
|
$q->update($rel->getTable()->getComponentName())
|
||||||
->set($rel->getForeign(), '?', array(null))
|
->set($rel->getForeign(), '?', array(null))
|
||||||
->addWhere($rel->getForeign() . ' = ?', array_values($this->identifier()))
|
->addWhere($rel->getForeign() . ' = ?', array_values($this->identifier()));
|
||||||
->whereIn($rel->getTable()->getIdentifier(), $ids);
|
|
||||||
|
if (count($ids) > 0) {
|
||||||
|
$q->whereIn($rel->getTable()->getIdentifier(), $ids);
|
||||||
|
}
|
||||||
|
|
||||||
$q->execute();
|
$q->execute();
|
||||||
}
|
}
|
||||||
|
@ -793,6 +793,13 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
|||||||
$this->assertEqual($user->Group[0]->identifier(), $group1->identifier());
|
$this->assertEqual($user->Group[0]->identifier(), $group1->identifier());
|
||||||
$this->assertEqual($user->Group[1]->identifier(), $group2->identifier());
|
$this->assertEqual($user->Group[1]->identifier(), $group2->identifier());
|
||||||
|
|
||||||
|
$user->unlink('Group');
|
||||||
|
$user->save();
|
||||||
|
unset($user);
|
||||||
|
|
||||||
|
$user = $this->objTable->find(5);
|
||||||
|
$this->assertEqual($user->Group->count(), 0);
|
||||||
|
|
||||||
|
|
||||||
// ACCESSING ASSOCIATION OBJECT PROPERTIES
|
// ACCESSING ASSOCIATION OBJECT PROPERTIES
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user