Skip to content
Permalink
Browse files

Unify marshalling with saving.

Unify how nested associations are defined in marshalling and saving.
Having two different formats makes it harder to remember and document
the various features of the Table class.
  • Loading branch information...
markstory committed Dec 21, 2013
1 parent 44cb684 commit 813708af838b95f265b255beab91286d267b1662
Showing with 6 additions and 3 deletions.
  1. +3 −0 Cake/ORM/Marshaller.php
  2. +2 −2 Cake/ORM/Table.php
  3. +1 −1 Cake/Test/TestCase/ORM/MarshallerTest.php
@@ -64,6 +64,7 @@ protected function _buildPropertyMap($include) {
$key = $nested;
$nested = [];
}
$nested = isset($nested['associated']) ? $nested['associated'] : [];
$assoc = $this->_table->association($key);
if ($assoc) {
$map[$assoc->property()] = [
@@ -81,6 +82,7 @@ protected function _buildPropertyMap($include) {
* @param array $data The data to hydrate.
* @param array $include The associations to include.
* @return Cake\ORM\Entity
* @see Cake\ORM\Table::newEntity()
*/
public function one(array $data, $include = []) {
$propertyMap = $this->_buildPropertyMap($include);
@@ -128,6 +130,7 @@ protected function _marshalAssociation($assoc, $value, $include) {
* @param array $data The data to hydrate.
* @param array $include The associations to include.
* @return array An array of hydrated records.
* @see Cake\ORM\Table::newEntities()
*/
public function many(array $data, $include = []) {
$output = [];
@@ -1490,7 +1490,7 @@ public function marshaller($safe = false) {
* {{{
* $articles = $this->Articles->newEntity(
* $this->request->data(),
* ['Tags', 'Comments' => ['Users']]
* ['Tags', 'Comments' => ['associated' => ['Users']]]
* );
* }}}
*
@@ -1524,7 +1524,7 @@ public function newEntity(array $data, $associations = null) {
* {{{
* $articles = $this->Articles->newEntities(
* $this->request->data(),
* ['Tags', 'Comments' => ['Users']]
* ['Tags', 'Comments' => ['associated' => ['Users']]]
* );
* }}}
*
@@ -193,7 +193,7 @@ public function testOneDeepAssociations() {
]
];
$marshall = new Marshaller($this->comments);
$result = $marshall->one($data, ['Articles' => ['Users']]);
$result = $marshall->one($data, ['Articles' => ['associated' => ['Users']]]);
$this->assertEquals(
$data['article']['title'],

0 comments on commit 813708a

Please sign in to comment.
You can’t perform that action at this time.