@@ -4917,10 +4917,13 @@ private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$
4917
4917
foreach ($ joins ->getKeys () as $ t2Name ) {
4918
4918
4919
4919
$ t2 = $ this ->reflection ->getTable ($ t2Name );
4920
+ $ t3 = null ;
4920
4921
4921
4922
$ belongsTo = count ($ t1 ->getFksTo ($ t2 ->getName ())) > 0 ;
4922
4923
$ hasMany = count ($ t2 ->getFksTo ($ t1 ->getName ())) > 0 ;
4923
- $ t3 = $ this ->hasAndBelongsToMany ($ t1 , $ t2 );
4924
+ if (!$ belongsTo && !$ hasMany ) {
4925
+ $ t3 = $ this ->hasAndBelongsToMany ($ t1 , $ t2 );
4926
+ }
4924
4927
$ hasAndBelongsToMany = ($ t3 != null );
4925
4928
4926
4929
$ newRecords = array ();
@@ -4931,10 +4934,12 @@ private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$
4931
4934
if ($ belongsTo ) {
4932
4935
$ fkValues = $ this ->getFkEmptyValues ($ t1 , $ t2 , $ records );
4933
4936
$ this ->addFkRecords ($ t2 , $ fkValues , $ params , $ db , $ newRecords );
4934
- } elseif ($ hasMany ) {
4937
+ }
4938
+ if ($ hasMany ) {
4935
4939
$ pkValues = $ this ->getPkEmptyValues ($ t1 , $ records );
4936
4940
$ this ->addPkRecords ($ t1 , $ t2 , $ pkValues , $ params , $ db , $ newRecords );
4937
- } elseif ($ hasAndBelongsToMany ) {
4941
+ }
4942
+ if ($ hasAndBelongsToMany ) {
4938
4943
$ habtmValues = $ this ->getHabtmEmptyValues ($ t1 , $ t2 , $ t3 , $ db , $ records );
4939
4944
$ this ->addFkRecords ($ t2 , $ habtmValues ->fkValues , $ params , $ db , $ newRecords );
4940
4945
}
@@ -4944,10 +4949,12 @@ private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$
4944
4949
if ($ fkValues != null ) {
4945
4950
$ this ->fillFkValues ($ t2 , $ newRecords , $ fkValues );
4946
4951
$ this ->setFkValues ($ t1 , $ t2 , $ records , $ fkValues );
4947
- } elseif ($ pkValues != null ) {
4952
+ }
4953
+ if ($ pkValues != null ) {
4948
4954
$ this ->fillPkValues ($ t1 , $ t2 , $ newRecords , $ pkValues );
4949
4955
$ this ->setPkValues ($ t1 , $ t2 , $ records , $ pkValues );
4950
- } elseif ($ habtmValues != null ) {
4956
+ }
4957
+ if ($ habtmValues != null ) {
4951
4958
$ this ->fillFkValues ($ t2 , $ newRecords , $ habtmValues ->fkValues );
4952
4959
$ this ->setHabtmValues ($ t1 , $ t3 , $ records , $ habtmValues );
4953
4960
}
0 commit comments