From 8655045097c26e280ec5f371df9857dec95721bd Mon Sep 17 00:00:00 2001 From: Joshua Sherman Date: Fri, 17 Jan 2014 15:46:57 -0500 Subject: [PATCH] Dropped database JOINs Not being used and the logic is pretty damn hacky. I don't believe in JOINs so I'm unsure if this support will be re-added in the future or if there will simply be a backed in opinion that JOINs are the devil. --- classes/Model.php | 58 +------------------------------------ tests/classes/ModelTest.php | 18 ------------ 2 files changed, 1 insertion(+), 75 deletions(-) diff --git a/classes/Model.php b/classes/Model.php index fdd92fd..763be58 100644 --- a/classes/Model.php +++ b/classes/Model.php @@ -122,16 +122,6 @@ class Model extends Object */ protected $table = false; - /** - * Joins - * - * SQL: JOIN - * - * @access protected - * @var mixed - */ - protected $joins = false; - /** * Conditions * @@ -692,52 +682,6 @@ class Model extends Object */ private function generateQuery() { - // Adds the JOIN syntax - // @todo Ton of issues with predefined columns - if ($this->joins != false) - { - if (is_array($this->joins)) - { - foreach ($this->joins as $join => $tables) - { - $join_pieces = [(stripos('JOIN ', $join) === false ? 'JOIN' : strtoupper($join))]; - - if (is_array($tables)) - { - foreach ($tables as $table => $conditions) - { - $join_pieces[] = $table; - - if (is_array($conditions)) - { - $type = strtoupper(key($conditions)); - $conditions = current($conditions); - - $join_pieces[] = $type; - $join_pieces[] = $this->generateConditions($conditions, true); - } - else - { - $join_pieces = $conditions; - } - } - } - else - { - $join_pieces[] = $tables; - } - } - - $this->sql[] = implode(' ', $join_pieces); - - unset($join_pieces); - } - else - { - $this->sql[] = (stripos('JOIN ', $this->joins) === false ? 'JOIN ' : '') . $this->joins; - } - } - // Adds the WHERE conditionals if ($this->conditions != false) { @@ -1621,7 +1565,7 @@ class Model extends Object $key = trim(strtolower($key)); // Assigns valid keys to the appropriate class property - if (in_array($key, ['fields', 'table', 'joins', 'conditions', 'group', 'having', 'order', 'limit', 'offset'])) + if (in_array($key, ['fields', 'table', 'conditions', 'group', 'having', 'order', 'limit', 'offset'])) { $this->$key = $value; $conditions = false; diff --git a/tests/classes/ModelTest.php b/tests/classes/ModelTest.php index 3a2bd86..51f0d3b 100644 --- a/tests/classes/ModelTest.php +++ b/tests/classes/ModelTest.php @@ -158,24 +158,6 @@ class ModelTest extends PHPUnit_Framework_TestCase $this->assertEquals([2 => 'one'], $model->records); } - public function testJoinsString() - { - $model = new MockModelWithoutColumns([ - 'conditions' => ['pickles.id' => 1], - 'joins' => 'brines ON brines.pickle_id = pickles.id', - ]); - } - - public function testJoinsArray() - { - $model = new MockModelWithoutColumns([ - 'conditions' => ['pickles.id' => 1], - 'joins' => [ - 'INNER JOIN' => 'brines ON brines.pickle_id = pickles.id', - ], - ]); - } - public function testFieldValues() { $model = new MockModel('all');