@@ -1784,7 +1784,7 @@ public function save($data = null, $validate = true, $fieldList = array()) {
1784
1784
if (empty ($ this ->data [$ this ->alias ][$ this ->primaryKey ])) {
1785
1785
unset($ this ->data [$ this ->alias ][$ this ->primaryKey ]);
1786
1786
}
1787
- $ fields = $ values = array ();
1787
+ $ joined = $ fields = $ values = array ();
1788
1788
1789
1789
foreach ($ this ->data as $ n => $ v ) {
1790
1790
if (isset ($ this ->hasAndBelongsToMany [$ n ])) {
@@ -1843,24 +1843,26 @@ public function save($data = null, $validate = true, $fieldList = array()) {
1843
1843
}
1844
1844
}
1845
1845
1846
- if (! empty ( $ joined ) && $ success === true ) {
1847
- $ this -> _saveMulti ( $ joined, $ this -> id , $ db );
1848
- }
1849
-
1850
- if ( $ success && $ count === 0 ) {
1851
- $ success = false ;
1846
+ if ($ success ) {
1847
+ if (! empty ( $ joined)) {
1848
+ $ this -> _saveMulti ( $ joined , $ this -> id , $ db );
1849
+ } else if ( $ count === 0 ) {
1850
+ $ success = false ;
1851
+ }
1852
1852
}
1853
1853
1854
- if ($ success && $ count > 0 ) {
1855
- if (!empty ($ this ->data )) {
1856
- if ($ created ) {
1857
- $ this ->data [$ this ->alias ][$ this ->primaryKey ] = $ this ->id ;
1854
+ if ($ success ) {
1855
+ if ($ count > 0 ) {
1856
+ if (!empty ($ this ->data )) {
1857
+ if ($ created ) {
1858
+ $ this ->data [$ this ->alias ][$ this ->primaryKey ] = $ this ->id ;
1859
+ }
1858
1860
}
1859
- }
1860
1861
1861
- if ($ options ['callbacks ' ] === true || $ options ['callbacks ' ] === 'after ' ) {
1862
- $ event = new CakeEvent ('Model.afterSave ' , $ this , array ($ created , $ options ));
1863
- $ this ->getEventManager ()->dispatch ($ event );
1862
+ if ($ options ['callbacks ' ] === true || $ options ['callbacks ' ] === 'after ' ) {
1863
+ $ event = new CakeEvent ('Model.afterSave ' , $ this , array ($ created , $ options ));
1864
+ $ this ->getEventManager ()->dispatch ($ event );
1865
+ }
1864
1866
}
1865
1867
1866
1868
if (!empty ($ this ->data )) {
0 commit comments