Skip to content

Commit

Permalink
Rename to onlyIds.
Browse files Browse the repository at this point in the history
This name better fits what the option actually does.
  • Loading branch information
markstory committed Sep 4, 2015
1 parent ee8436b commit 63722de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/ORM/Marshaller.php
Expand Up @@ -94,12 +94,12 @@ protected function _buildPropertyMap($options)
* * accessibleFields: A list of fields to allow or deny in entity accessible fields.
*
* The above options can be used in each nested `associated` array. In addition to the above
* options you can also use the `ids` option for HasMany and BelongsToMany associations.
* options you can also use the `onlyIds` option for HasMany and BelongsToMany associations.
* When true this option restricts the request data to only be read from `_ids`.
*
* ```
* $result = $marshaller->one($data, [
* 'associated' => ['Tags' => ['ids' => true]]
* 'associated' => ['Tags' => ['onlyIds' => true]]
* ]);
* ```
*
Expand Down Expand Up @@ -235,12 +235,12 @@ protected function _marshalAssociation($assoc, $value, $options)
}
if ($assoc->type() === Association::ONE_TO_MANY || $assoc->type() === Association::MANY_TO_MANY) {
$hasIds = array_key_exists('_ids', $value);
$idsOption = array_key_exists('ids', $options) && $options['ids'];
$onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];

if ($hasIds && is_array($value['_ids'])) {
return $this->_loadAssociatedByIds($assoc, $value['_ids']);
}
if ($hasIds || $idsOption) {
if ($hasIds || $onlyIds) {
return [];
}
}
Expand Down Expand Up @@ -423,12 +423,12 @@ protected function _loadBelongsToMany($assoc, $ids)
* * accessibleFields: A list of fields to allow or deny in entity accessible fields.
*
* The above options can be used in each nested `associated` array. In addition to the above
* options you can also use the `ids` option for HasMany and BelongsToMany associations.
* options you can also use the `onlyIds` option for HasMany and BelongsToMany associations.
* When true this option restricts the request data to only be read from `_ids`.
*
* ```
* $result = $marshaller->merge($entity, $data, [
* 'associated' => ['Tags' => ['ids' => true]]
* 'associated' => ['Tags' => ['onlyIds' => true]]
* ]);
* ```
*
Expand Down Expand Up @@ -646,12 +646,12 @@ protected function _mergeBelongsToMany($original, $assoc, $value, $options)
$associated = isset($options['associated']) ? $options['associated'] : [];

$hasIds = array_key_exists('_ids', $value);
$idsOption = array_key_exists('ids', $options) && $options['ids'];
$onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];

if ($hasIds && is_array($value['_ids'])) {
return $this->_loadAssociatedByIds($assoc, $value['_ids']);
}
if ($hasIds || $idsOption) {
if ($hasIds || $onlyIds) {
return [];
}

Expand Down
18 changes: 9 additions & 9 deletions tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -491,7 +491,7 @@ public function testOneBelongsToManyJoinData()
}

/**
* Test that the ids option restricts to only accepting ids for belongs to many associations.
* Test that the onlyIds option restricts to only accepting ids for belongs to many associations.
*
* @return void
*/
Expand All @@ -508,13 +508,13 @@ public function testOneBelongsToManyOnlyIdsRejectArray()
];
$marshall = new Marshaller($this->articles);
$result = $marshall->one($data, [
'associated' => ['Tags' => ['ids' => true]]
'associated' => ['Tags' => ['onlyIds' => true]]
]);
$this->assertEmpty($result->tags, 'Only ids should be marshalled.');
}

/**
* Test that the ids option restricts to only accepting ids for belongs to many associations.
* Test that the onlyIds option restricts to only accepting ids for belongs to many associations.
*
* @return void
*/
Expand All @@ -531,7 +531,7 @@ public function testOneBelongsToManyOnlyIdsWithIds()
];
$marshall = new Marshaller($this->articles);
$result = $marshall->one($data, [
'associated' => ['Tags' => ['ids' => true]]
'associated' => ['Tags' => ['onlyIds' => true]]
]);
$this->assertCount(2, $result->tags, 'Ids should be marshalled.');
}
Expand Down Expand Up @@ -872,7 +872,7 @@ public function testOneHasManyWithIds()
}

/**
* Test that the ids option restricts to only accepting ids for hasmany associations.
* Test that the onlyIds option restricts to only accepting ids for hasmany associations.
*
* @return void
*/
Expand All @@ -889,13 +889,13 @@ public function testOneHasManyOnlyIdsRejectArray()

$marshaller = new Marshaller($this->articles);
$article = $marshaller->one($data, [
'associated' => ['Comments' => ['ids' => true]]
'associated' => ['Comments' => ['onlyIds' => true]]
]);
$this->assertEmpty($article->comments);
}

/**
* Test that the ids option restricts to only accepting ids for hasmany associations.
* Test that the onlyIds option restricts to only accepting ids for hasmany associations.
*
* @return void
*/
Expand All @@ -912,7 +912,7 @@ public function testOneHasManyOnlyIdsWithIds()

$marshaller = new Marshaller($this->articles);
$article = $marshaller->one($data, [
'associated' => ['Comments' => ['ids' => true]]
'associated' => ['Comments' => ['onlyIds' => true]]
]);
$this->assertCount(2, $article->comments);
}
Expand Down Expand Up @@ -1623,7 +1623,7 @@ public function testMergeBelongsToManyOnlyIdsRejectArray()
$entity->accessible('*', true);
$marshall = new Marshaller($this->articles);
$result = $marshall->merge($entity, $data, [
'associated' => ['Tags' => ['ids' => true]]
'associated' => ['Tags' => ['onlyIds' => true]]
]);
$this->assertCount(0, $result->tags);
}
Expand Down

0 comments on commit 63722de

Please sign in to comment.