@@ -32,27 +32,29 @@ class BelongsToManyThrough extends Sql\Relations\Abstracts\AbstractRelation
3232 */
3333 public function getResult ()
3434 {
35- if ($ this ->map ->currentModel ->row instanceof Sql \DataObjects \Result \Row) {
36- $ criteria = $ this ->map ->currentModel ->row ->offsetGet ($ this ->map ->currentPrimaryKey );
37- $ field = $ this ->map ->currentTable . '. ' . $ this ->map ->currentPrimaryKey ;
35+ if ($ this ->map ->objectModel ->row instanceof Sql \DataObjects \Result \Row) {
36+ $ criteria = $ this ->map ->objectModel ->row ->offsetGet ($ this ->map ->objectPrimaryKey );
37+ $ conditions = [
38+ $ this ->map ->objectTable . '. ' . $ this ->map ->objectPrimaryKey => $ criteria ,
39+ ];
3840
39- $ this ->map ->referenceModel ->qb
41+ $ this ->map ->associateModel ->qb
4042 ->select ([
41- $ this ->map ->referenceTable . '.* ' ,
43+ $ this ->map ->associateTable . '.* ' ,
4244 ])
43- ->join ($ this ->map ->currentTable , implode (' = ' , [
44- $ this ->map ->currentTable . '. ' . $ this ->map ->currentPrimaryKey ,
45- $ this ->map ->intermediaryTable . '. ' . $ this ->map ->intermediaryCurrentForeignKey ,
45+ ->join ($ this ->map ->objectTable , implode (' = ' , [
46+ $ this ->map ->objectTable . '. ' . $ this ->map ->objectPrimaryKey ,
47+ $ this ->map ->intermediaryTable . '. ' . $ this ->map ->intermediaryForeignKey ,
4648 ]))
47- ->join ($ this ->map ->referenceTable , implode (' = ' , [
48- $ this ->map ->referenceTable . '. ' . $ this ->map ->referencePrimaryKey ,
49- $ this ->map ->intermediaryTable . '. ' . $ this ->map ->intermediaryReferenceForeignKey ,
49+ ->join ($ this ->map ->associateTable , implode (' = ' , [
50+ $ this ->map ->associateTable . '. ' . $ this ->map ->associatePrimaryKey ,
51+ $ this ->map ->intermediaryTable . '. ' . $ this ->map ->intermediaryAssociateForeignKey ,
5052 ]));
5153
5254 $ this ->map ->intermediaryModel ->result = null ;
5355 $ this ->map ->intermediaryModel ->row = null ;
5456
55- if ($ result = $ this ->map ->intermediaryModel ->find ( $ criteria , $ field )) {
57+ if ($ result = $ this ->map ->intermediaryModel ->findWhere ( $ conditions )) {
5658 return $ result ;
5759 }
5860 }
0 commit comments