File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -557,6 +557,51 @@ public function testOneBelongsToManyJoinDataAssociatedWithIds()
557
557
$ this ->assertEquals ($ data ['tags ' ][5 ]['_joinData ' ]['user ' ]['username ' ], $ result ->tags [1 ]->_joinData ->user ->username );
558
558
}
559
559
560
+ /**
561
+ * Test belongsToMany association with mixed data array
562
+ *
563
+ * @return void
564
+ */
565
+ public function testBelongsToManyWithMixedData ()
566
+ {
567
+
568
+ $ data = [
569
+ 'title ' => 'My title ' ,
570
+ 'body ' => 'My content ' ,
571
+ 'author_id ' => 1 ,
572
+ 'tags ' => [
573
+ [
574
+ 'name ' => 'tag4 '
575
+ ],
576
+ [
577
+ 'name ' => 'tag5 '
578
+ ],
579
+ [
580
+ 'id ' => 1
581
+ ]
582
+ ]
583
+ ];
584
+
585
+ $ articles = TableRegistry::get ('Articles ' );
586
+ $ articles ->belongsToMany ('Tags ' );
587
+
588
+ $ tags = TableRegistry::get ('Tags ' );
589
+
590
+ $ article = $ articles ->newEntity ($ data , [
591
+ 'associated ' => [
592
+ 'Tags '
593
+ ]
594
+ ]);
595
+
596
+ $ this ->assertEquals ($ article ->tags [2 ], $ tags ->get (1 ));
597
+
598
+ $ tag_count = $ tags ->find ()->count ();
599
+ $ articles ->save ($ article );
600
+
601
+ $ this ->assertEquals ($ tag_count + 2 , $ tags ->find ()->count ());
602
+
603
+ }
604
+
560
605
/**
561
606
* Test HasMany association with _ids attribute
562
607
*
You can’t perform that action at this time.
0 commit comments