summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamie Matthews <[email protected]>2010-10-25 18:37:37 +0100
committerJamie Matthews <[email protected]>2010-10-25 18:37:37 +0100
commite305fcaf7446818c7ddd498ca950b0d4fd595570 (patch)
tree27ef929f816de92599bdec1e26676d90fef1f5f7
parent31558e93f67c17b715741f395699fc902d9bd552 (diff)
Add inner, left outer, right outer, full outer joins
-rw-r--r--idiorm.php28
-rw-r--r--test/test_queries.php16
2 files changed, 44 insertions, 0 deletions
diff --git a/idiorm.php b/idiorm.php
index ca1adfc..4ac01f8 100644
--- a/idiorm.php
+++ b/idiorm.php
@@ -449,6 +449,34 @@
}
/**
+ * Add an INNER JOIN souce to the query
+ */
+ public function inner_join($table, $constraint, $table_alias=null) {
+ return $this->_add_join_source("INNER", $table, $constraint, $table_alias);
+ }
+
+ /**
+ * Add a LEFT OUTER JOIN souce to the query
+ */
+ public function left_outer_join($table, $constraint, $table_alias=null) {
+ return $this->_add_join_source("LEFT OUTER", $table, $constraint, $table_alias);
+ }
+
+ /**
+ * Add an RIGHT OUTER JOIN souce to the query
+ */
+ public function right_outer_join($table, $constraint, $table_alias=null) {
+ return $this->_add_join_source("RIGHT OUTER", $table, $constraint, $table_alias);
+ }
+
+ /**
+ * Add an FULL OUTER JOIN souce to the query
+ */
+ public function full_outer_join($table, $constraint, $table_alias=null) {
+ return $this->_add_join_source("FULL OUTER", $table, $constraint, $table_alias);
+ }
+
+ /**
* Internal method to add a WHERE condition to the query
*/
protected function _add_where($fragment, $values) {
diff --git a/test/test_queries.php b/test/test_queries.php
index ea7ae44..cc73452 100644
--- a/test/test_queries.php
+++ b/test/test_queries.php
@@ -124,6 +124,22 @@
$expected = "SELECT * FROM `widget` JOIN `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`";
Tester::check_equal("Simple join", $expected);
+ ORM::for_table('widget')->inner_join('widget_handle', array('widget_handle.widget_id', '=', 'widget.id'))->find_many();
+ $expected = "SELECT * FROM `widget` INNER JOIN `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`";
+ Tester::check_equal("Inner join", $expected);
+
+ ORM::for_table('widget')->left_outer_join('widget_handle', array('widget_handle.widget_id', '=', 'widget.id'))->find_many();
+ $expected = "SELECT * FROM `widget` LEFT OUTER JOIN `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`";
+ Tester::check_equal("Left outer join", $expected);
+
+ ORM::for_table('widget')->right_outer_join('widget_handle', array('widget_handle.widget_id', '=', 'widget.id'))->find_many();
+ $expected = "SELECT * FROM `widget` RIGHT OUTER JOIN `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`";
+ Tester::check_equal("Right outer join", $expected);
+
+ ORM::for_table('widget')->full_outer_join('widget_handle', array('widget_handle.widget_id', '=', 'widget.id'))->find_many();
+ $expected = "SELECT * FROM `widget` FULL OUTER JOIN `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`";
+ Tester::check_equal("Full outer join", $expected);
+
$widget = ORM::for_table('widget')->create();
$widget->name = "Fred";
$widget->age = 10;