diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-01-21 21:27:09 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-01-21 21:27:09 +0000 |
commit | e58a9c509b0a864aee583dd14a018a773dbc63e4 (patch) | |
tree | 916532fa2abed9b0344c874ef8e70bb92e3fa16f | |
parent | a0456a9a47d35aa8a3776d6b5fea0e68706855d8 (diff) |
Update Kohana to r3918
-rw-r--r-- | kohana/config/inflector.php | 1 | ||||
-rw-r--r-- | kohana/libraries/Model.php | 3 | ||||
-rw-r--r-- | kohana/libraries/ORM.php | 52 | ||||
-rw-r--r-- | kohana/libraries/Validation.php | 2 | ||||
-rw-r--r-- | kohana/libraries/drivers/Database/Mysql.php | 2 | ||||
-rw-r--r-- | kohana/libraries/drivers/Database/Mysqli.php | 13 |
6 files changed, 39 insertions, 34 deletions
diff --git a/kohana/config/inflector.php b/kohana/config/inflector.php index 64c0853c..6dcfc2d3 100644 --- a/kohana/config/inflector.php +++ b/kohana/config/inflector.php @@ -54,4 +54,5 @@ $config['irregular'] = array 'ox' => 'oxen', 'leaf' => 'leaves', 'course' => 'courses', + 'size' => 'sizes', ); diff --git a/kohana/libraries/Model.php b/kohana/libraries/Model.php index 45a561c2..4134ff2d 100644 --- a/kohana/libraries/Model.php +++ b/kohana/libraries/Model.php @@ -6,11 +6,12 @@ * * @package Core * @author Kohana Team - * @copyright (c) 2007-2008 Kohana Team + * @copyright (c) 2007-2009 Kohana Team * @license http://kohanaphp.com/license.html */ class Model_Core { + // Database object protected $db; /** diff --git a/kohana/libraries/ORM.php b/kohana/libraries/ORM.php index 0783ebcd..16ac16f2 100644 --- a/kohana/libraries/ORM.php +++ b/kohana/libraries/ORM.php @@ -323,7 +323,7 @@ class ORM_Core { // Load the remote model, always singular $model = ORM::factory(inflector::singular($column)); - if ($this->has($model)) + if ($this->has($model, TRUE)) { // many<>many relationship return $this->related[$column] = $model @@ -909,19 +909,12 @@ class ORM_Core { * Tests if this object has a relationship to a different model. * * @param object related ORM model + * @param boolean check for any relations to given model * @return boolean */ - public function has(ORM $model) + public function has(ORM $model, $any = FALSE) { - if ($model->table_names_plural) - { - // Get the plural object name as the related name - $related = $model->object_plural; - } - else - { - $related = $model->object_name; - } + $related = $model->object_plural; if (($join_table = array_search($related, $this->has_and_belongs_to_many)) === FALSE) return FALSE; @@ -938,15 +931,20 @@ class ORM_Core { $this->changed_relations[$related] = $this->object_relations[$related] = $this->load_relations($join_table, $model); } - if ($model->loaded) + if ( ! $model->empty_primary_key()) { // Check if a specific object exists return in_array($model->primary_key_value, $this->changed_relations[$related]); } - else + elseif ($any) { + // Check if any relations to given model exist return ! empty($this->changed_relations[$related]); } + else + { + return FALSE; + } } /** @@ -989,19 +987,11 @@ class ORM_Core { // Get the faked column name $column = $model->object_plural; - if ($model->loaded) - { - if (($key = array_search($model->primary_key_value, $this->changed_relations[$column])) === FALSE) - return FALSE; + if (($key = array_search($model->primary_key_value, $this->changed_relations[$column])) === FALSE) + return FALSE; - // Remove the relationship - unset($this->changed_relations[$column][$key]); - } - else - { - // Clear all of this objects relationships - $this->changed_relations[$column] = array(); - } + // Remove the relationship + unset($this->changed_relations[$column][$key]); if (isset($this->related[$column])) { @@ -1251,7 +1241,7 @@ class ORM_Core { $this->object = $this->changed = $this->related = array(); // Set the loaded and saved object status based on the primary key - $this->loaded = $this->saved = (bool) $values[$this->primary_key]; + $this->loaded = $this->saved = ($values[$this->primary_key] !== NULL); } // Related objects @@ -1449,4 +1439,14 @@ class ORM_Core { return $relations; } + /** + * Returns whether or not primary key is empty + * + * @return bool + */ + protected function empty_primary_key() + { + return (empty($this->object[$this->primary_key]) AND $this->object[$this->primary_key] !== '0'); + } + } // End ORM diff --git a/kohana/libraries/Validation.php b/kohana/libraries/Validation.php index c89e66f6..473425db 100644 --- a/kohana/libraries/Validation.php +++ b/kohana/libraries/Validation.php @@ -205,7 +205,7 @@ class Validation_Core extends ArrayObject { { if (is_string($callback)) { - if (strpos('::', $callback) !== FALSE) + if (strpos($callback, '::') !== FALSE) { $callback = explode('::', $callback); } diff --git a/kohana/libraries/drivers/Database/Mysql.php b/kohana/libraries/drivers/Database/Mysql.php index c24dfec3..f54b6d81 100644 --- a/kohana/libraries/drivers/Database/Mysql.php +++ b/kohana/libraries/drivers/Database/Mysql.php @@ -325,7 +325,7 @@ class Database_Mysql_Driver extends Database_Driver { if ($query = mysql_query('SHOW COLUMNS FROM '.$this->escape_table($table), $this->link)) { - if (mysql_num_rows($query) > 0) + if (mysql_num_rows($query)) { while ($row = mysql_fetch_object($query)) { diff --git a/kohana/libraries/drivers/Database/Mysqli.php b/kohana/libraries/drivers/Database/Mysqli.php index 206d42f2..795c576b 100644 --- a/kohana/libraries/drivers/Database/Mysqli.php +++ b/kohana/libraries/drivers/Database/Mysqli.php @@ -114,15 +114,18 @@ class Database_Mysqli_Driver extends Database_Mysql_Driver { public function field_data($table) { - $query = $this->link->query('SHOW COLUMNS FROM '.$this->escape_table($table)); + $columns = array(); + $query = $this->link->query('SHOW COLUMNS FROM '.$this->escape_table($table)); - $table = array(); - while ($row = $query->fetch_object()) + if (is_object($query)) { - $table[] = $row; + while ($row = $query->fetch_object()) + { + $columns[] = $row; + } } - return $table; + return $columns; } } // End Database_Mysqli_Driver Class |