diff options
-rw-r--r-- | README.markdown | 1 | ||||
-rw-r--r-- | idiorm.php | 4 | ||||
-rw-r--r-- | test/test_queries.php | 4 |
3 files changed, 9 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown index 51b5b74..971e685 100644 --- a/README.markdown +++ b/README.markdown @@ -37,6 +37,7 @@ Changelog * Add support for `MIN`, `AVG`, `MAX` and `SUM` - closes issue #16 * Add `group_by_expr` - closes issue #24 * Add `set_expr` to allow database expressions to be set as ORM properties - closes issues #59 and #43 [[brianherbert](https://github.com/brianherbert)] +* Prevent ambiguous column names when joining tables - issue #66 [[hellogerard](https://github.com/hellogerard)] #### 1.1.1 - release 2011-01-30 @@ -729,6 +729,10 @@ * of the call to _quote_identifier */ protected function _add_simple_where($column_name, $separator, $value) { + // Add the table name in case of ambiguous columns + if (count($this->_join_sources) > 0 && strpos($column_name, '.') === false) { + $column_name = "{$this->_table_name}.{$column_name}"; + } $column_name = $this->_quote_identifier($column_name); return $this->_add_where("{$column_name} {$separator} ?", $value); } diff --git a/test/test_queries.php b/test/test_queries.php index b0dc88b..1f2acc6 100644 --- a/test/test_queries.php +++ b/test/test_queries.php @@ -192,6 +192,10 @@ $expected = "SELECT * FROM `widget` JOIN `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id`"; Tester::check_equal("Simple join", $expected); + ORM::for_table('widget')->join('widget_handle', array('widget_handle.widget_id', '=', 'widget.id'))->find_one(5); + $expected = "SELECT * FROM `widget` JOIN `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id` WHERE `widget`.`id` = '5' LIMIT 1"; + Tester::check_equal("Simple join with where_id_is method", $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); |