From 148302e9f6f6861179e60549b5af9dd11526f4de Mon Sep 17 00:00:00 2001 From: KTP95 Date: Tue, 29 Dec 2015 17:36:08 +0100 Subject: [PATCH 1/2] Solve Bug in join to table without primaryKey --- dbObject.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dbObject.php b/dbObject.php index 56d2e94a..3821fb9e 100644 --- a/dbObject.php +++ b/dbObject.php @@ -17,7 +17,7 @@ * @method mixed paginate (int $page, array $fields) * @method dbObject query ($query, $numRows) * @method dbObject rawQuery ($query, $bindParams, $sanitize) - * @method dbObject join (string $objectName, string $key, string $joinType) + * @method dbObject join (string $objectName, string $key, string $joinType, string $primaryKey) * @method dbObject with (string $objectName) * @method dbObject groupBy (string $groupByField) * @method dbObject orderBy ($orderByField, $orderbyDirection, $customFields) @@ -391,15 +391,19 @@ private function with ($objectName) { * @param string $objectName Object Name * @param string $key Key for a join from primary object * @param string $joinType SQL join type: LEFT, RIGHT, INNER, OUTER + * @param string $primaryKey SQL join On Second primaryKey * * @return dbObject */ - private function join ($objectName, $key = null, $joinType = 'LEFT') { + private function join ($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) { $joinObj = new $objectName; if (!$key) $key = $objectName . "id"; + if (!$primaryKey) + $primaryKey = $joinObj->primaryKey; + $joinStr = MysqliDb::$prefix . $this->dbTable . ".{$key} = " . - MysqliDb::$prefix . "{$joinObj->dbTable}.{$joinObj->primaryKey}"; + MysqliDb::$prefix . "{$joinObj->dbTable}.{$primaryKey}"; $this->db->join ($joinObj->dbTable, $joinStr, $joinType); return $this; } From 5e7b3337fddafba3ee54c1ece74ddaf76bd4c1bc Mon Sep 17 00:00:00 2001 From: KTP95 Date: Wed, 30 Dec 2015 03:03:02 +0100 Subject: [PATCH 2/2] Update dbObject.php --- dbObject.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbObject.php b/dbObject.php index 3821fb9e..253f5d5e 100644 --- a/dbObject.php +++ b/dbObject.php @@ -391,7 +391,7 @@ private function with ($objectName) { * @param string $objectName Object Name * @param string $key Key for a join from primary object * @param string $joinType SQL join type: LEFT, RIGHT, INNER, OUTER - * @param string $primaryKey SQL join On Second primaryKey + * @param string $primaryKey SQL join On Second primaryKey * * @return dbObject */ @@ -399,7 +399,7 @@ private function join ($objectName, $key = null, $joinType = 'LEFT', $primaryKey $joinObj = new $objectName; if (!$key) $key = $objectName . "id"; - if (!$primaryKey) + if (!$primaryKey) $primaryKey = $joinObj->primaryKey; $joinStr = MysqliDb::$prefix . $this->dbTable . ".{$key} = " .