Skip to content

Commit 148302e

Browse files
committed
Solve Bug in join to table without primaryKey
1 parent dad6618 commit 148302e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

dbObject.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @method mixed paginate (int $page, array $fields)
1818
* @method dbObject query ($query, $numRows)
1919
* @method dbObject rawQuery ($query, $bindParams, $sanitize)
20-
* @method dbObject join (string $objectName, string $key, string $joinType)
20+
* @method dbObject join (string $objectName, string $key, string $joinType, string $primaryKey)
2121
* @method dbObject with (string $objectName)
2222
* @method dbObject groupBy (string $groupByField)
2323
* @method dbObject orderBy ($orderByField, $orderbyDirection, $customFields)
@@ -391,15 +391,19 @@ private function with ($objectName) {
391391
* @param string $objectName Object Name
392392
* @param string $key Key for a join from primary object
393393
* @param string $joinType SQL join type: LEFT, RIGHT, INNER, OUTER
394+
* @param string $primaryKey SQL join On Second primaryKey
394395
*
395396
* @return dbObject
396397
*/
397-
private function join ($objectName, $key = null, $joinType = 'LEFT') {
398+
private function join ($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) {
398399
$joinObj = new $objectName;
399400
if (!$key)
400401
$key = $objectName . "id";
402+
if (!$primaryKey)
403+
$primaryKey = $joinObj->primaryKey;
404+
401405
$joinStr = MysqliDb::$prefix . $this->dbTable . ".{$key} = " .
402-
MysqliDb::$prefix . "{$joinObj->dbTable}.{$joinObj->primaryKey}";
406+
MysqliDb::$prefix . "{$joinObj->dbTable}.{$primaryKey}";
403407
$this->db->join ($joinObj->dbTable, $joinStr, $joinType);
404408
return $this;
405409
}

0 commit comments

Comments
 (0)