@@ -32,27 +32,29 @@ class BelongsToManyThrough extends Sql\Relations\Abstracts\AbstractRelation
32
32
*/
33
33
public function getResult ()
34
34
{
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
+ ];
38
40
39
- $ this ->map ->referenceModel ->qb
41
+ $ this ->map ->associateModel ->qb
40
42
->select ([
41
- $ this ->map ->referenceTable . '.* ' ,
43
+ $ this ->map ->associateTable . '.* ' ,
42
44
])
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 ,
46
48
]))
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 ,
50
52
]));
51
53
52
54
$ this ->map ->intermediaryModel ->result = null ;
53
55
$ this ->map ->intermediaryModel ->row = null ;
54
56
55
- if ($ result = $ this ->map ->intermediaryModel ->find ( $ criteria , $ field )) {
57
+ if ($ result = $ this ->map ->intermediaryModel ->findWhere ( $ conditions )) {
56
58
return $ result ;
57
59
}
58
60
}
0 commit comments