From 721154b01441db5fefaf62e9f2ea2c990a4a0d37 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 1 Jun 2011 16:27:55 +0300 Subject: fixed find_children with OrderBy table name --- MainController.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/MainController.php b/MainController.php index de69e9a..a426018 100644 --- a/MainController.php +++ b/MainController.php @@ -210,13 +210,13 @@ class MainController foreach ($fk as $child) { $order_by = ''; - - if ($ob = $child::OrderBy) { - $order_by = sprintf('ORDER BY `%s`.%s', $child, $ob); - } $table = ($child::TableName) ? $child::TableName : $child; + if ($ob = $child::OrderBy) { + $order_by = sprintf('ORDER BY `%s`.%s', $table, $ob); + } + // determine nature of relationship $one_to_many = explode(',', $child::ForeignKey); $many_to_many = explode(',', $child::ManyToMany); @@ -226,14 +226,15 @@ class MainController if (in_array($this->table, $many_to_many)) // m/n { $sql = "SELECT `{$table}`.*, `{$table}_{$this->table}`.*, - `{$table}_{$this->table}`.id AS {$table}_{$this->table}_id, - `{$table}`.* - FROM `{$table}_{$this->table}`, `{$this->table}`, `$table` - WHERE `{$table}_{$this->table}`.`{$this->table}_id` = `$this->table`.id AND - `{$table}_{$this->table}`.`{$table}_id` = `$table`.id AND - `{$this->table}`.id = ?"; - } else if (@in_array($table, $ref_schema['belongsTo'])) { // 1/m - $sql = "SELECT * FROM `$ref` WHERE `$ref`.`{$table}_id` = ?"; + `{$table}_{$this->table}`.id AS {$table}_{$this->table}_id, + `{$table}`.* + FROM `{$table}_{$this->table}`, `{$this->table}`, `$table` + WHERE `{$table}_{$this->table}`.`{$this->table}_id` = `$this->table`.id AND + `{$table}_{$this->table}`.`{$table}_id` = `$table`.id AND + `{$this->table}`.id = ?"; + } + else if (@in_array($table, $ref_schema['belongsTo'])) { // 1/m + $sql = "SELECT * FROM `$ref` WHERE `$ref`.`{$table}_id` = ?"; } $stmt = MainDb::query($sql, array($id)); @@ -439,7 +440,7 @@ class MainController } //// - // insert or update + // Insert or update public function upsert($data, $where = NULL) { if(!$this->get($where)) { -- cgit v1.2.3