Skip to content

Commit

Permalink
Fix up phpcs errors and add missing documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 27, 2016
1 parent d2b6376 commit 3a097c1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
38 changes: 25 additions & 13 deletions src/ORM/Marshaller.php
Expand Up @@ -86,10 +86,15 @@ protected function _buildPropertyMap($options)
*
* ### Options:
*
* * associated: Associations listed here will be marshalled as well.
* * fieldList: A whitelist of fields to be assigned to the entity. If not present,
* the accessible fields list in the entity will be used.
* * accessibleFields: A list of fields to allow or deny in entity accessible fields.
* - validate: Set to false to disable validation. Can also be a string of the validator ruleset to be applied.
* Defaults to true/default.
* - associated: Associations listed here will be marshalled as well. Defaults to null.
* - fieldList: A whitelist of fields to be assigned to the entity. If not present,
* the accessible fields list in the entity will be used. Defaults to null.
* - accessibleFields: A list of fields to allow or deny in entity accessible fields. Defaults to null
* - forceNew: When enabled, belongsToMany associations will have 'new' entities created
* when primary key values are set, and a record does not already exist. Normally primary key
* on missing entities would be ignored. Defaults to false.
*
* The above options can be used in each nested `associated` array. In addition to the above
* options you can also use the `onlyIds` option for HasMany and BelongsToMany associations.
Expand Down Expand Up @@ -258,10 +263,15 @@ protected function _marshalAssociation($assoc, $value, $options)
*
* ### Options:
*
* * associated: Associations listed here will be marshalled as well.
* * fieldList: A whitelist of fields to be assigned to the entity. If not present,
* the accessible fields list in the entity will be used.
* * accessibleFields: A list of fields to allow or deny in entity accessible fields.
* - validate: Set to false to disable validation. Can also be a string of the validator ruleset to be applied.
* Defaults to true/default.
* - associated: Associations listed here will be marshalled as well. Defaults to null.
* - fieldList: A whitelist of fields to be assigned to the entity. If not present,
* the accessible fields list in the entity will be used. Defaults to null.
* - accessibleFields: A list of fields to allow or deny in entity accessible fields. Defaults to null
* - forceNew: When enabled, belongsToMany associations will have 'new' entities created
* when primary key values are set, and a record does not already exist. Normally primary key
* on missing entities would be ignored. Defaults to false.
*
* @param array $data The data to hydrate.
* @param array $options List of options
Expand Down Expand Up @@ -315,7 +325,7 @@ protected function _belongsToMany(Association $assoc, array $data, $options = []
foreach ($keys as $key => $value) {
$rowConditions[][$target->aliasfield($key)] = $value;
}

if ($forceNew && !$target->exists($rowConditions)) {
$records[$i] = $this->one($row, $options);
}
Expand Down Expand Up @@ -431,12 +441,12 @@ protected function _loadBelongsToMany($assoc, $ids)
*
* ### Options:
*
* * associated: Associations listed here will be marshalled as well.
* * validate: Whether or not to validate data before hydrating the entities. Can
* - associated: Associations listed here will be marshalled as well.
* - validate: Whether or not to validate data before hydrating the entities. Can
* also be set to a string to use a specific validator. Defaults to true/default.
* * fieldList: A whitelist of fields to be assigned to the entity. If not present
* - fieldList: A whitelist of fields to be assigned to the entity. If not present
* the accessible fields list in the entity will be used.
* * accessibleFields: A list of fields to allow or deny in entity accessible fields.
* - 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 `onlyIds` option for HasMany and BelongsToMany associations.
Expand Down Expand Up @@ -543,6 +553,8 @@ public function merge(EntityInterface $entity, array $data, array $options = [])
*
* ### Options:
*
* - validate: Whether or not to validate data before hydrating the entities. Can
* also be set to a string to use a specific validator. Defaults to true/default.
* - associated: Associations listed here will be marshalled as well.
* - fieldList: A whitelist of fields to be assigned to the entity. If not present,
* the accessible fields list in the entity will be used.
Expand Down
21 changes: 11 additions & 10 deletions tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -849,11 +849,11 @@ public function testBelongsToManyWithMixedData()
$this->assertEquals($tagCount + 2, $tags->find()->count());
}

/**
* Test belongsToMany association with the ForceNewTarget to force saving
* new records on the target tables with BTM relationships when the primaryKey(s)
* of the target table is specified.
*
/**
* Test belongsToMany association with the ForceNewTarget to force saving
* new records on the target tables with BTM relationships when the primaryKey(s)
* of the target table is specified.
*
* @return void
*/
public function testBelongsToManyWithForceNew()
Expand All @@ -864,11 +864,11 @@ public function testBelongsToManyWithForceNew()
'author_id' => 1,
'tags' => [
[
'id' => 3
'id' => 3
],
[
'id' => 4,
'name' => 'tag4'
'id' => 4,
'name' => 'tag4'
]
]
];
Expand All @@ -881,8 +881,9 @@ public function testBelongsToManyWithForceNew()

$this->assertFalse($article->tags[0]->isNew(), 'The tag should not be new');
$this->assertTrue($article->tags[1]->isNew(), 'The tag should be new');
}

$this->assertSame('tag4', $article->tags[1]->name, 'Property should match request data.');
}

/**
* Test HasMany association with _ids attribute
*
Expand Down

0 comments on commit 3a097c1

Please sign in to comment.