@@ -4917,10 +4917,13 @@ private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$
49174917 foreach ($ joins ->getKeys () as $ t2Name ) {
49184918
49194919 $ t2 = $ this ->reflection ->getTable ($ t2Name );
4920+ $ t3 = null ;
49204921
49214922 $ belongsTo = count ($ t1 ->getFksTo ($ t2 ->getName ())) > 0 ;
49224923 $ hasMany = count ($ t2 ->getFksTo ($ t1 ->getName ())) > 0 ;
4923- $ t3 = $ this ->hasAndBelongsToMany ($ t1 , $ t2 );
4924+ if (!$ belongsTo && !$ hasMany ) {
4925+ $ t3 = $ this ->hasAndBelongsToMany ($ t1 , $ t2 );
4926+ }
49244927 $ hasAndBelongsToMany = ($ t3 != null );
49254928
49264929 $ newRecords = array ();
@@ -4931,10 +4934,12 @@ private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$
49314934 if ($ belongsTo ) {
49324935 $ fkValues = $ this ->getFkEmptyValues ($ t1 , $ t2 , $ records );
49334936 $ this ->addFkRecords ($ t2 , $ fkValues , $ params , $ db , $ newRecords );
4934- } elseif ($ hasMany ) {
4937+ }
4938+ if ($ hasMany ) {
49354939 $ pkValues = $ this ->getPkEmptyValues ($ t1 , $ records );
49364940 $ this ->addPkRecords ($ t1 , $ t2 , $ pkValues , $ params , $ db , $ newRecords );
4937- } elseif ($ hasAndBelongsToMany ) {
4941+ }
4942+ if ($ hasAndBelongsToMany ) {
49384943 $ habtmValues = $ this ->getHabtmEmptyValues ($ t1 , $ t2 , $ t3 , $ db , $ records );
49394944 $ this ->addFkRecords ($ t2 , $ habtmValues ->fkValues , $ params , $ db , $ newRecords );
49404945 }
@@ -4944,10 +4949,12 @@ private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$
49444949 if ($ fkValues != null ) {
49454950 $ this ->fillFkValues ($ t2 , $ newRecords , $ fkValues );
49464951 $ this ->setFkValues ($ t1 , $ t2 , $ records , $ fkValues );
4947- } elseif ($ pkValues != null ) {
4952+ }
4953+ if ($ pkValues != null ) {
49484954 $ this ->fillPkValues ($ t1 , $ t2 , $ newRecords , $ pkValues );
49494955 $ this ->setPkValues ($ t1 , $ t2 , $ records , $ pkValues );
4950- } elseif ($ habtmValues != null ) {
4956+ }
4957+ if ($ habtmValues != null ) {
49514958 $ this ->fillFkValues ($ t2 , $ newRecords , $ habtmValues ->fkValues );
49524959 $ this ->setHabtmValues ($ t1 , $ t3 , $ records , $ habtmValues );
49534960 }
0 commit comments