pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/cakephp/cakephp/pull/18988.diff

should be dirty'); + $this->assertSame('newuser', $tag->articles[0]->user->username); + $this->assertTrue($tag->articles[0]->user->isNew()); + + $this->assertNotEmpty($tag->articles[0]->comments); + $this->assertCount(2, $tag->articles[0]->comments); + $this->assertTrue($tag->articles[0]->isDirty('comments'), 'Updated prop should be dirty'); + $this->assertInstanceOf(Entity::class, $tag->articles[0]->comments[0]); + $this->assertTrue($tag->articles[0]->comments[0]->isNew()); + $this->assertTrue($tag->articles[0]->comments[1]->isNew()); + } + /** * Test belongsToMany association with mixed data and _joinData */ @@ -2285,6 +2339,65 @@ public function testMergeBelongsToManyJoinDataAssociatedWithIdsWithoutDotNotatio ); } + /** + * Test the unified array structure similar to contain() for merge operations. + * This verifies that the same nested format works for merging as it does for marshalling. + */ + public function testMergeBelongsToManyJoinDataAssociatedWithIdsUnifiedFormat(): void + { + $data = [ + 'title' => 'My title', + 'tags' => [ + [ + 'id' => 1, + '_joinData' => [ + 'active' => 1, + 'user' => ['username' => 'MyLux'], + ], + ], + [ + 'id' => 2, + '_joinData' => [ + 'active' => 0, + 'user' => ['username' => 'IronFall'], + ], + ], + ], + ]; + $articlesTags = $this->getTableLocator()->get('ArticlesTags'); + $articlesTags->belongsTo('Users'); + + $marshall = new Marshaller($this->articles); + $article = $this->articles->get(1, ...['associated' => 'Tags']); + // Using the unified format like contain() with dot notation for single association + $result = $marshall->merge($article, $data, ['associated' => [ + 'Tags._joinData.Users', + ]]); + + $this->assertTrue($result->isDirty('tags')); + $this->assertInstanceOf(Entity::class, $result->tags[0]); + $this->assertInstanceOf(Entity::class, $result->tags[1]); + $this->assertInstanceOf(Entity::class, $result->tags[0]->_joinData->user); + + $this->assertInstanceOf(Entity::class, $result->tags[1]->_joinData->user); + $this->assertFalse($result->tags[0]->isNew(), 'Should not be new, as id is in db.'); + $this->assertFalse($result->tags[1]->isNew(), 'Should not be new, as id is in db.'); + $this->assertSame(1, $result->tags[0]->id); + $this->assertSame(2, $result->tags[1]->id); + + $this->assertSame(1, $result->tags[0]->_joinData->active); + $this->assertSame(0, $result->tags[1]->_joinData->active); + + $this->assertSame( + $data['tags'][0]['_joinData']['user']['username'], + $result->tags[0]->_joinData->user->username, + ); + $this->assertSame( + $data['tags'][1]['_joinData']['user']['username'], + $result->tags[1]->_joinData->user->username, + ); + } + /** * Test merging the _joinData entity for belongstomany associations. */ pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy