Created
December 23, 2011 21:38
-
-
Save tholder/1515424 to your computer and use it in GitHub Desktop.
Puling an array item matching a value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function testPullTest() | |
{ | |
$doc = new Model_Mongo_Lab(); | |
$doc->laboratory = new Shanty_Mongo_Document(); | |
$doc->laboratory->mixtures = array( | |
array( | |
'id' => 'abc', | |
'name' => 'string 1' | |
), | |
array( | |
'id' => '123', | |
'name' => 'string 2' | |
), | |
); | |
$doc->save(); | |
$loadedDoc = Model_Mongo_Lab::find($doc->getId()); | |
$this->assertEquals('string 1', $loadedDoc->laboratory->mixtures[0]->name); | |
$doc->addOperation('$pull', 'laboratory.mixtures', array('id'=> 'abc')); | |
$doc->save(); | |
$loadedDoc = Model_Mongo_Lab::find($doc->getId()); | |
$this->assertEquals('string 2', $loadedDoc->laboratory->mixtures[0]->name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment