Skip to content

Commit

Permalink
Straighten removing strategy from collection field
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Jul 23, 2015
1 parent f3ea0fc commit 1dd07bb
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 10 deletions.
Expand Up @@ -27,5 +27,4 @@ abstract class AbstractField extends Annotation
public $type = 'string';
public $nullable = false;
public $options = array();
public $strategy;
}
3 changes: 2 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
Expand Up @@ -1044,7 +1044,8 @@ private function prepareQueryElement($fieldName, $value = null, $class = null, $
return array($fieldName, $value);
}

if ($mapping['strategy'] === 'set' && isset($e[2])) {
if (isset($mapping['strategy']) && CollectionHelper::isHash($mapping['strategy'])
&& isset($e[2])) {
$objectProperty = $e[2];
$objectPropertyPrefix = $e[1] . '.';
$nextObjectProperty = implode('.', array_slice($e, 3));
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/UnitOfWork.php
Expand Up @@ -907,7 +907,7 @@ private function computeAssociationChanges($parentDocument, array $assoc, $value
$state = $this->getDocumentState($entry, self::STATE_NEW);

// Handle "set" strategy for multi-level hierarchy
$pathKey = CollectionHelper::isList($assoc['strategy']) ? $count : $key;
$pathKey = ! isset($assoc['strategy']) || CollectionHelper::isList($assoc['strategy']) ? $count : $key;
$path = $assoc['type'] === 'many' ? $assoc['name'] . '.' . $pathKey : $assoc['name'];

$count++;
Expand Down Expand Up @@ -2696,7 +2696,7 @@ private function scheduleCollectionOwner(PersistentCollection $coll)
while (null !== ($parentAssoc = $this->getParentAssociation($parent))) {
list($mapping, $parent, ) = $parentAssoc;
}
if (CollectionHelper::isAtomic($mapping['strategy'])) {
if (isset($mapping['strategy']) && CollectionHelper::isAtomic($mapping['strategy'])) {
$class = $this->dm->getClassMetadata(get_class($document));
$atomicCollection = $class->getFieldValue($document, $mapping['fieldName']);
$this->scheduleCollectionUpdate($atomicCollection);
Expand Down
Expand Up @@ -271,10 +271,10 @@ class GH453Document
/** @ODM\Hash */
public $hash;

/** @ODM\Collection(strategy="pushAll")) */
/** @ODM\Collection() */
public $colPush;

/** @ODM\Collection(strategy="set") */
/** @ODM\Collection() */
public $colSet;

/** @ODM\EmbedMany(strategy="pushAll")) */
Expand Down
Expand Up @@ -40,12 +40,14 @@ public function testDocumentCollectionNameAndInheritance($class)
*/
public function testFieldMappings($class)
{
$this->assertEquals(13, count($class->fieldMappings));
$this->assertEquals(14, count($class->fieldMappings));
$this->assertTrue(isset($class->fieldMappings['id']));
$this->assertTrue(isset($class->fieldMappings['version']));
$this->assertTrue(isset($class->fieldMappings['lock']));
$this->assertTrue(isset($class->fieldMappings['name']));
$this->assertTrue(isset($class->fieldMappings['email']));
$this->assertTrue(isset($class->fieldMappings['roles']));
$this->assertFalse(isset($class->fieldMappings['roles']['strategy']));

return $class;
}
Expand Down Expand Up @@ -141,7 +143,7 @@ public function testLockFieldMappings($class)
*/
public function testAssocations($class)
{
$this->assertEquals(13, count($class->fieldMappings));
$this->assertEquals(14, count($class->fieldMappings));

return $class;
}
Expand Down Expand Up @@ -400,6 +402,11 @@ class AbstractMappingDriverUser
*/
public $createdAt;

/**
* @ODM\Collection
*/
public $roles = array();

/**
* @ODM\PrePersist
*/
Expand Down
Expand Up @@ -18,6 +18,7 @@
<field fieldName="email" type="string" unique="true" drop-dups="true" order="desc" />
<field fieldName="mysqlProfileId" type="integer" unique="true" drop-dups="true" order="desc" />
<field fieldName="createdAt" type="date" />
<field fieldName="roles" type="collection" />
<indexes>
<index unique="true">
<key name="username" order="desc" />
Expand Down
Expand Up @@ -31,6 +31,8 @@ Doctrine\ODM\MongoDB\Tests\Mapping\AbstractMappingDriverUser:
index:
order: asc
expireAfterSeconds: 3600
roles:
type: collection
indexes:
index1:
keys:
Expand Down
2 changes: 1 addition & 1 deletion tests/Documents/Article.php
Expand Up @@ -22,7 +22,7 @@ class Article
/** @ODM\Date */
private $createdAt;

/** @ODM\Field(type="collection", strategy="set") */
/** @ODM\Field(type="collection") */
private $tags = array();

public function getId()
Expand Down
2 changes: 1 addition & 1 deletion tests/Documents/Strategy.php
Expand Up @@ -10,7 +10,7 @@ class Strategy
/** @ODM\Id */
public $id;

/** @ODM\Collection(strategy="set") */
/** @ODM\Collection() */
public $logs = array();

/** @ODM\EmbedMany(targetDocument="Message", strategy="set") */
Expand Down

0 comments on commit 1dd07bb

Please sign in to comment.