Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using with, columns are joined with :, but not escaped. #115

Open
jimktrains opened this issue Apr 10, 2015 · 0 comments
Open

When using with, columns are joined with :, but not escaped. #115

jimktrains opened this issue Apr 10, 2015 · 0 comments

Comments

@jimktrains
Copy link
Contributor

When creating column names for with(), : is used to join the table and column, the column name now needs to be escape in databases such as Postgres, since : isn't a valid identifier ins ANSI SQL. A possible solution could be to use ___ (3 underscores) as the separator to avoid having to rework many things. A possible patch is included.

:100644 100644 5418cdd... 0000000... M  modules/orm/classes/Kohana/ORM.php

diff --git a/modules/orm/classes/Kohana/ORM.php b/modules/orm/classes/Kohana/ORM.php
index 5418cdd..6e900f1 100644
--- a/modules/orm/classes/Kohana/ORM.php
+++ b/modules/orm/classes/Kohana/ORM.php
@@ -849,7 +849,7 @@ class Kohana_ORM extends Model implements serializable {
                }

                // Split object parts
-               $aliases = explode(':', $target_path);
+               $aliases = explode('___', $target_path);
                $target = $this;
                foreach ($aliases as $alias)
                {
@@ -869,7 +869,7 @@ class Kohana_ORM extends Model implements serializable {

                // Pop-off top alias to get the parent path (user:photo:tag becomes user:photo - the parent table prefix)
                array_pop($aliases);
-               $parent_path = implode(':', $aliases);
+               $parent_path = implode('___', $aliases);

                if (empty($parent_path))
                {
@@ -892,7 +892,7 @@ class Kohana_ORM extends Model implements serializable {
                foreach (array_keys($target->_object) as $column)
                {
                        $name = $target_path.'.'.$column;
-                       $alias = $target_path.':'.$column;
+                       $alias = $target_path.'___'.$column;

                        // Add the prefix so that load_result can determine the relationship
                        $this->select(array($name, $alias));
@@ -1119,7 +1119,7 @@ class Kohana_ORM extends Model implements serializable {

                foreach ($values as $column => $value)
                {
-                       if (strpos($column, ':') === FALSE)
+                       if (strpos($column, '___') === FALSE)
                        {
                                // Load the value to this model
                                $this->_object[$column] = $value;
@@ -1127,7 +1127,7 @@ class Kohana_ORM extends Model implements serializable {
                        else
                        {
                                // Column belongs to a related model
-                               list ($prefix, $column) = explode(':', $column, 2);
+                               list ($prefix, $column) = explode('___', $column, 2);

                                $related[$prefix][$column] = $value;
                        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant