Fixed default value support + camelCase column problems
This commit is contained in:
parent
75284895d3
commit
ddbf6c949b
@ -57,8 +57,8 @@ class Doctrine_Locking_Manager_Pessimistic
|
|||||||
if($this->_dataSource->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true)
|
if($this->_dataSource->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true)
|
||||||
{
|
{
|
||||||
$columns = array();
|
$columns = array();
|
||||||
$columns['object_type'] = array('string', 50, array('notnull' => true, 'primary'));
|
$columns['object_type'] = array('string', 50, array('notnull' => true, 'primary' => true));
|
||||||
$columns['object_key'] = array('string', 250, array('notnull' => true, 'primary'));
|
$columns['object_key'] = array('string', 250, array('notnull' => true, 'primary' => true));
|
||||||
$columns['user_ident'] = array('string', 50, array('notnull' => true));
|
$columns['user_ident'] = array('string', 50, array('notnull' => true));
|
||||||
$columns['timestamp_obtained'] = array('integer', 10, array('notnull' => true));
|
$columns['timestamp_obtained'] = array('integer', 10, array('notnull' => true));
|
||||||
|
|
||||||
|
@ -253,8 +253,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
if($default === null)
|
if($default === null)
|
||||||
$default = self::$null;
|
$default = self::$null;
|
||||||
|
|
||||||
if($value === self::$null || $overwrite)
|
if($value === self::$null || $overwrite) {
|
||||||
$this->data[$column] = $default;
|
$this->data[$column] = $default;
|
||||||
|
$this->modified[] = $column;
|
||||||
|
$this->state = Doctrine_Record::STATE_TDIRTY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -281,35 +284,31 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
foreach($this->table->getColumnNames() as $name) {
|
foreach($this->table->getColumnNames() as $name) {
|
||||||
$type = $this->table->getTypeOf($name);
|
$type = $this->table->getTypeOf($name);
|
||||||
|
|
||||||
$lower = strtolower($name);
|
if( ! isset($tmp[$name])) {
|
||||||
|
|
||||||
if( ! isset($tmp[$lower])) {
|
|
||||||
//if($type == 'array') {
|
|
||||||
// $this->data[$name] = array();
|
|
||||||
//} else
|
|
||||||
$this->data[$name] = self::$null;
|
$this->data[$name] = self::$null;
|
||||||
} else {
|
} else {
|
||||||
switch($type):
|
switch($type):
|
||||||
case "array":
|
case "array":
|
||||||
case "object":
|
case "object":
|
||||||
|
|
||||||
if($tmp[$lower] !== self::$null) {
|
if($tmp[$name] !== self::$null) {
|
||||||
if(is_string($tmp[$lower])) {
|
if(is_string($tmp[$name])) {
|
||||||
$value = unserialize($tmp[$lower]);
|
$value = unserialize($tmp[$name]);
|
||||||
|
|
||||||
if($value === false)
|
if($value === false)
|
||||||
throw new Doctrine_Record_Exception("Unserialization of $name failed. ".var_dump($tmp[$lower],true));
|
throw new Doctrine_Record_Exception("Unserialization of $name failed. ".var_dump($tmp[$lower],true));
|
||||||
} else
|
} else
|
||||||
$value = $tmp[$lower];
|
$value = $tmp[$name];
|
||||||
|
|
||||||
$this->data[$name] = $value;
|
$this->data[$name] = $value;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "enum":
|
case "enum":
|
||||||
$this->data[$name] = $this->table->enumValue($name, $tmp[$lower]);
|
|
||||||
|
$this->data[$name] = $this->table->enumValue($name, $tmp[$name]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->data[$name] = $tmp[$lower];
|
$this->data[$name] = $tmp[$name];
|
||||||
endswitch;
|
endswitch;
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
@ -601,36 +600,34 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
*/
|
*/
|
||||||
public function get($name, $invoke = true) {
|
public function get($name, $invoke = true) {
|
||||||
$listener = $this->table->getAttribute(Doctrine::ATTR_LISTENER);
|
$listener = $this->table->getAttribute(Doctrine::ATTR_LISTENER);
|
||||||
|
|
||||||
$value = self::$null;
|
$value = self::$null;
|
||||||
|
$lower = strtolower($name);
|
||||||
|
|
||||||
|
if(isset($this->data[$lower])) {
|
||||||
if(isset($this->data[$name])) {
|
|
||||||
|
|
||||||
// check if the property is null (= it is the Doctrine_Null object located in self::$null)
|
// check if the property is null (= it is the Doctrine_Null object located in self::$null)
|
||||||
if($this->data[$name] === self::$null) {
|
if($this->data[$lower] === self::$null) {
|
||||||
$this->load();
|
$this->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->data[$name] === self::$null)
|
if($this->data[$lower] === self::$null)
|
||||||
$value = null;
|
$value = null;
|
||||||
else
|
else
|
||||||
$value = $this->data[$name];
|
$value = $this->data[$lower];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if($value !== self::$null) {
|
if($value !== self::$null) {
|
||||||
if($invoke && $name !== $this->table->getIdentifier()) {
|
if($invoke && $name !== $this->table->getIdentifier()) {
|
||||||
|
|
||||||
return $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onGetProperty($this, $name, $value);
|
return $this->table->getAttribute(Doctrine::ATTR_LISTENER)->onGetProperty($this, $name, $value);
|
||||||
} else
|
} else
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(isset($this->id[$name]))
|
if(isset($this->id[$lower]))
|
||||||
return $this->id[$name];
|
return $this->id[$lower];
|
||||||
|
|
||||||
if($name === $this->table->getIdentifier())
|
if($name === $this->table->getIdentifier())
|
||||||
return null;
|
return null;
|
||||||
@ -706,7 +703,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function set($name,$value) {
|
public function set($name,$value) {
|
||||||
if(isset($this->data[$name])) {
|
$lower = strtolower($name);
|
||||||
|
|
||||||
|
if(isset($this->data[$lower])) {
|
||||||
|
|
||||||
if($value instanceof Doctrine_Record) {
|
if($value instanceof Doctrine_Record) {
|
||||||
$id = $value->getIncremented();
|
$id = $value->getIncremented();
|
||||||
@ -715,7 +714,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
$value = $id;
|
$value = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$old = $this->get($name, false);
|
$old = $this->get($lower, false);
|
||||||
|
|
||||||
if($old !== $value) {
|
if($old !== $value) {
|
||||||
|
|
||||||
@ -725,8 +724,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
if($value === null)
|
if($value === null)
|
||||||
$value = self::$null;
|
$value = self::$null;
|
||||||
|
|
||||||
$this->data[$name] = $value;
|
$this->data[$lower] = $value;
|
||||||
$this->modified[] = $name;
|
$this->modified[] = $lower;
|
||||||
switch($this->state):
|
switch($this->state):
|
||||||
case Doctrine_Record::STATE_CLEAN:
|
case Doctrine_Record::STATE_CLEAN:
|
||||||
case Doctrine_Record::STATE_PROXY:
|
case Doctrine_Record::STATE_PROXY:
|
||||||
|
@ -291,7 +291,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
|||||||
unset($options[$k]);
|
unset($options[$k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$name = strtolower($name);
|
||||||
$this->columns[$name] = array($type,$length,$options);
|
$this->columns[$name] = array($type,$length,$options);
|
||||||
|
|
||||||
if(isset($options['primary'])) {
|
if(isset($options['primary'])) {
|
||||||
@ -318,6 +318,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getDefaultValueOf($column) {
|
public function getDefaultValueOf($column) {
|
||||||
|
$column = strtolower($column);
|
||||||
if( ! isset($this->columns[$column]))
|
if( ! isset($this->columns[$column]))
|
||||||
throw new Doctrine_Table_Exception("Couldn't get default value. Column ".$column." doesn't exist.");
|
throw new Doctrine_Table_Exception("Couldn't get default value. Column ".$column." doesn't exist.");
|
||||||
|
|
||||||
@ -680,7 +681,11 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
|||||||
$this->relations[$alias] = $relation;
|
$this->relations[$alias] = $relation;
|
||||||
return $this->relations[$alias];
|
return $this->relations[$alias];
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
throw new Doctrine_Table_Exception($this->name . " doesn't have a relation to " . $original);
|
throw new Doctrine_Table_Exception($this->name . " doesn't have a relation to " . $original);
|
||||||
|
} catch(Exception $e) {
|
||||||
|
print $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* returns an array containing all foreign key objects
|
* returns an array containing all foreign key objects
|
||||||
@ -922,7 +927,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
final public function setEnumValues($field, array $values) {
|
final public function setEnumValues($field, array $values) {
|
||||||
$this->enum[$field] = $values;
|
$this->enum[strtolower($field)] = $values;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param string $field
|
* @param string $field
|
||||||
@ -936,12 +941,20 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* enumValue
|
* enumValue
|
||||||
|
*
|
||||||
|
* @param string $field
|
||||||
|
* @param integer $index
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
final public function enumValue($field, $index) {
|
final public function enumValue($field, $index) {
|
||||||
return isset($this->enum[$field][$index])?$this->enum[$field][$index]:$index;
|
return isset($this->enum[$field][$index])?$this->enum[$field][$index]:$index;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* enumIndex
|
* enumIndex
|
||||||
|
*
|
||||||
|
* @param string $field
|
||||||
|
* @param mixed $value
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
final public function enumIndex($field, $value) {
|
final public function enumIndex($field, $value) {
|
||||||
if( ! isset($this->enum[$field]))
|
if( ! isset($this->enum[$field]))
|
||||||
|
@ -5,13 +5,10 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
|
|||||||
$this->tables[] = "FieldNameTest";
|
$this->tables[] = "FieldNameTest";
|
||||||
parent::prepareTables();
|
parent::prepareTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFieldConversion() {
|
public function testFieldConversion() {
|
||||||
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
|
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
|
||||||
|
|
||||||
$user = $this->connection->getTable('User')->find(5);
|
|
||||||
|
|
||||||
$this->assertTrue($user instanceof User);
|
|
||||||
|
|
||||||
$t = new FieldNameTest();
|
$t = new FieldNameTest();
|
||||||
|
|
||||||
$t->someColumn = 'abc';
|
$t->someColumn = 'abc';
|
||||||
@ -55,6 +52,7 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
|
|||||||
|
|
||||||
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
|
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBind() {
|
public function testBind() {
|
||||||
$table = $this->connection->getTable("User");
|
$table = $this->connection->getTable("User");
|
||||||
}
|
}
|
||||||
@ -150,5 +148,6 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
|
|||||||
public function testApplyInheritance() {
|
public function testApplyInheritance() {
|
||||||
$this->assertEqual($this->objTable->applyInheritance("id = 3"), "id = 3 AND type = ?");
|
$this->assertEqual($this->objTable->applyInheritance("id = 3"), "id = 3 AND type = ?");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user