aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2011-06-01 16:27:55 +0300
committerFilipp Lepalaan <filipp@mac.com>2011-06-01 16:27:55 +0300
commit721154b01441db5fefaf62e9f2ea2c990a4a0d37 (patch)
tree735909730ca1b53f3b18c7b4cd8fa67096765943
parent4b4c5271adf657331c867e79f88044d3317901ef (diff)
downloadmain-721154b01441db5fefaf62e9f2ea2c990a4a0d37.tar.gz
main-721154b01441db5fefaf62e9f2ea2c990a4a0d37.tar.bz2
main-721154b01441db5fefaf62e9f2ea2c990a4a0d37.zip
fixed find_children with OrderBy table name
-rw-r--r--MainController.php27
1 files 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)) {