Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NATURAL JOIN support #640

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions MysqliDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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])) {
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down