3
3
namespace TheCodingMachine \TDBM \Utils ;
4
4
5
5
use Doctrine \DBAL \Connection ;
6
+ use Doctrine \DBAL \Platforms \AbstractPlatform ;
6
7
use Doctrine \DBAL \Schema \ForeignKeyConstraint ;
7
8
use TheCodingMachine \TDBM \ResultIterator ;
8
9
use TheCodingMachine \TDBM \TDBMInvalidArgumentException ;
13
14
class ManyToManyRelationshipPathDescriptor
14
15
{
15
16
/**
16
- * @var string
17
+ * @var string Unquoted identifier of the target table
17
18
*/
18
19
private $ targetTable ;
19
20
/**
20
- * @var string
21
+ * @var string Unquoted identifier of the pivot table
21
22
*/
22
23
private $ pivotTable ;
23
24
/**
@@ -69,7 +70,12 @@ public function getTargetName(): string
69
70
return $ this ->targetTable ;
70
71
}
71
72
72
- public function getPivotFrom (Connection $ connection ): string
73
+ /**
74
+ * Get the `FROM` clause of the query.
75
+ *
76
+ * This may have issue handling namespaced table (e.g. mydb.table)
77
+ */
78
+ public function getPivotFrom (AbstractPlatform $ platform ): string
73
79
{
74
80
$ mainTable = $ this ->targetTable ;
75
81
$ pivotTable = $ this ->pivotTable ;
@@ -78,21 +84,26 @@ public function getPivotFrom(Connection $connection): string
78
84
foreach ($ this ->joinForeignKeys as $ key => $ column ) {
79
85
$ join [] = sprintf (
80
86
'%s.%s = %s.%s ' ,
81
- $ connection ->quoteIdentifier ($ mainTable ),
82
- $ connection ->quoteIdentifier ($ column ),
83
- $ connection ->quoteIdentifier ($ pivotTable ),
84
- $ connection ->quoteIdentifier ($ this ->joinLocalKeys [$ key ])
87
+ $ platform ->quoteIdentifier ($ mainTable ),
88
+ $ platform ->quoteIdentifier ($ column ),
89
+ $ platform ->quoteIdentifier ($ pivotTable ),
90
+ $ platform ->quoteIdentifier ($ this ->joinLocalKeys [$ key ])
85
91
);
86
92
}
87
93
88
- return $ connection ->quoteIdentifier ($ mainTable ) . ' JOIN ' . $ connection ->quoteIdentifier ($ pivotTable ) . ' ON ' . implode (' AND ' , $ join );
94
+ return $ platform ->quoteIdentifier ($ mainTable ) . ' JOIN ' . $ platform ->quoteIdentifier ($ pivotTable ) . ' ON ' . implode (' AND ' , $ join );
89
95
}
90
96
91
- public function getPivotWhere (Connection $ connection ): string
97
+ /**
98
+ * Get the `WHERE` clause of the query.
99
+ *
100
+ * This may have issue handling namespaced table (e.g. mydb.table)
101
+ */
102
+ public function getPivotWhere (AbstractPlatform $ platform ): string
92
103
{
93
104
$ paramList = [];
94
105
foreach ($ this ->whereKeys as $ key => $ column ) {
95
- $ paramList [] = sprintf ('%s.%s = :param%s ' , $ connection ->quoteIdentifier ($ this ->pivotTable ), $ connection ->quoteIdentifier ($ column ), $ key );
106
+ $ paramList [] = sprintf ('%s.%s = :param%s ' , $ platform ->quoteIdentifier ($ this ->pivotTable ), $ platform ->quoteIdentifier ($ column ), $ key );
96
107
}
97
108
return implode (' AND ' , $ paramList );
98
109
}
0 commit comments