diff --git a/MysqliDb.php b/MysqliDb.php index a90e2805..d10528c8 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -942,9 +942,9 @@ public function orHaving($havingProp, $havingValue = null, $operator = null) * @throws Exception * @return MysqliDb */ - public function join($joinTable, $joinCondition, $joinType = '') + public function join($joinTable, $joinCondition = NULL, $joinType = 'NATURAL') { - $allowedTypes = array('LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'); + $allowedTypes = array('NATURAL', 'LEFT', 'RIGHT', 'OUTER', 'INNER', 'LEFT OUTER', 'RIGHT OUTER'); $joinType = strtoupper(trim($joinType)); if ($joinType && !in_array($joinType, $allowedTypes)) { @@ -2298,7 +2298,7 @@ protected function _buildJoin () { else $joinStr = $joinTable; - $this->_query .= " " . $joinType. " JOIN " . $joinStr ." on " . $joinCondition; + $this->_query .= " " . $joinType. " JOIN " . $joinStr . ($joinCondition ? " on " . $joinCondition : ""); // Add join and query if (!empty($this->_joinAnd) && isset($this->_joinAnd[$joinStr])) { diff --git a/readme.md b/readme.md index 7e2b16e0..3310c11d 100644 --- a/readme.md +++ b/readme.md @@ -600,6 +600,14 @@ print_r ($products); // Gives: SELECT u.login, p.productName FROM products p LEFT JOIN users u ON (p.tenantID=u.tenantID OR u.tenantID = 5) ``` +### NATURAL JOIN method +```php +$db->join("users"); +$products = $db->get ("products"); +print_r ($products); +// Gives: SELECT * FROM products NATURAL JOIN users +``` + ### Properties sharing Its is also possible to copy properties