File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -383,6 +383,21 @@ protected function _setRuntimeData(Model $Model) {
383
383
$ this ->runtime [$ Model ->alias ]['beforeSave ' ] = $ tempData ;
384
384
}
385
385
386
+ /**
387
+ * Restores model data to the original data.
388
+ * This solves issues with saveAssociated and validate = first.
389
+ *
390
+ * @param Model $model
391
+ * @return void
392
+ */
393
+ public function afterValidate (Model $ Model ) {
394
+ $ Model ->data [$ Model ->alias ] = array_merge (
395
+ $ Model ->data [$ Model ->alias ],
396
+ $ this ->runtime [$ Model ->alias ]['beforeSave ' ]
397
+ );
398
+ return true ;
399
+ }
400
+
386
401
/**
387
402
* afterSave Callback
388
403
*
Original file line number Diff line number Diff line change @@ -530,6 +530,38 @@ public function testSaveCreate() {
530
530
$ this ->assertEquals ($ expected , $ result );
531
531
}
532
532
533
+ /**
534
+ * testSaveAssociatedCreate method
535
+ *
536
+ * @return void
537
+ */
538
+ public function testSaveAssociatedMultipleLocale () {
539
+ $ this ->loadFixtures ('Translate ' , 'TranslatedItem ' );
540
+
541
+ $ TestModel = new TranslatedItem ();
542
+ $ data = array (
543
+ 'slug ' => 'fourth_translated ' ,
544
+ 'title ' => array (
545
+ 'eng ' => 'Title #4 ' ,
546
+ 'spa ' => 'Leyenda #4 ' ,
547
+ ),
548
+ 'content ' => array (
549
+ 'eng ' => 'Content #4 ' ,
550
+ 'spa ' => 'Contenido #4 ' ,
551
+ ),
552
+ 'translated_article_id ' => 1 ,
553
+ );
554
+ $ TestModel ->create ();
555
+ $ TestModel ->saveAssociated ($ data );
556
+
557
+ $ translations = array ('title ' => 'Title ' , 'content ' => 'Content ' );
558
+ $ TestModel ->bindTranslation ($ translations , false );
559
+ $ TestModel ->locale = array ('eng ' , 'spa ' );
560
+ $ result = $ TestModel ->read ();
561
+ $ this ->assertCount (2 , $ result ['Title ' ]);
562
+ $ this ->assertCount (2 , $ result ['Content ' ]);
563
+ }
564
+
533
565
/**
534
566
* Test that saving only some of the translated fields allows the record to be found again.
535
567
*
You can’t perform that action at this time.
0 commit comments