aboutsummaryrefslogtreecommitdiffstats
path: root/MainController.php
diff options
context:
space:
mode:
Diffstat (limited to 'MainController.php')
-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)) {