Skip to content

Commit

Permalink
1. Adjustment of code to work with multiple raw_joins 2. Test multipl…
Browse files Browse the repository at this point in the history
…e raw joins
  • Loading branch information
moiseevigor authored and treffynnon committed Apr 26, 2014
1 parent 7f8aa93 commit fd1fa80
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ public function raw_join($table, $constraint, $table_alias, $parameters = array(
$table .= " {$table_alias}";
}

$this->_values = $parameters;
$this->_values = array_merge($this->_values, $parameters);

// Build the constraint
if (is_array($constraint)) {
Expand Down
10 changes: 10 additions & 0 deletions test/QueryBuilderPsr1Test53.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ public function testRawJoinWithParameters() {
$this->assertEquals($expected, ORM::getLastQuery());
}

public function testRawJoinAndRawWhereWithParameters() {
ORM::forTable('widget')
->rawJoin('INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE ? AND `widget_handle`.category = ?)', array('widget_handle.widget_id', '=', 'widget.id'), 'widget_handle', array('%button%', 2))
->rawJoin('INNER JOIN ( SELECT * FROM `person` WHERE `person`.name LIKE ?)', array('person.id', '=', 'widget.person_id'), 'person', array('%Fred%'))
->whereRaw('`id` > ? AND `id` < ?', array(5, 10))
->findMany();
$expected = "SELECT * FROM `widget` INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE '%button%' AND `widget_handle`.category = '2') `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id` INNER JOIN ( SELECT * FROM `person` WHERE `person`.name LIKE '%Fred%') `person` ON `person`.`id` = `widget`.`person_id` WHERE `id` > '5' AND `id` < '10'";
$this->assertEquals($expected, ORM::getLastQuery());
}

public function testSelectWithDistinct() {
ORM::forTable('widget')->distinct()->select('name')->findMany();
$expected = "SELECT DISTINCT `name` FROM `widget`";
Expand Down
10 changes: 10 additions & 0 deletions test/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ public function testRawJoinWithParameters() {
$this->assertEquals($expected, ORM::get_last_query());
}

public function testRawJoinAndRawWhereWithParameters() {
ORM::for_table('widget')
->raw_join('INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE ? AND `widget_handle`.category = ?)', array('widget_handle.widget_id', '=', 'widget.id'), 'widget_handle', array('%button%', 2))
->raw_join('INNER JOIN ( SELECT * FROM `person` WHERE `person`.name LIKE ?)', array('person.id', '=', 'widget.person_id'), 'person', array('%Fred%'))
->where_raw('`id` > ? AND `id` < ?', array(5, 10))
->find_many();
$expected = "SELECT * FROM `widget` INNER JOIN ( SELECT * FROM `widget_handle` WHERE `widget_handle`.name LIKE '%button%' AND `widget_handle`.category = '2') `widget_handle` ON `widget_handle`.`widget_id` = `widget`.`id` INNER JOIN ( SELECT * FROM `person` WHERE `person`.name LIKE '%Fred%') `person` ON `person`.`id` = `widget`.`person_id` WHERE `id` > '5' AND `id` < '10'";
$this->assertEquals($expected, ORM::get_last_query());
}

public function testSelectWithDistinct() {
ORM::for_table('widget')->distinct()->select('name')->find_many();
$expected = "SELECT DISTINCT `name` FROM `widget`";
Expand Down

0 comments on commit fd1fa80

Please sign in to comment.