Commit bafcd662 authored by doctrine's avatar doctrine

--no commit message

--no commit message
parent ff9c9d84
...@@ -119,9 +119,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -119,9 +119,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
foreach($this->getNormalIterator() as $record) { foreach($this->getNormalIterator() as $record) {
if($value !== null) { if($value !== null) {
$record->set($this->reference_field, $value); $record->rawSet($this->reference_field, $value);
} else { } else {
$record->set($this->reference_field, $this->reference); $record->rawSet($this->reference_field, $this->reference);
} }
} }
} }
...@@ -284,9 +284,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -284,9 +284,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$value = $this->reference->get($this->relation->getLocal()); $value = $this->reference->get($this->relation->getLocal());
if($value !== null) { if($value !== null) {
$this->data[$key]->set($this->reference_field, $value); $this->data[$key]->rawSet($this->reference_field, $value);
} else { } else {
$this->data[$key]->set($this->reference_field, $this->reference); $this->data[$key]->rawSet($this->reference_field, $this->reference);
} }
} }
} }
......
...@@ -142,7 +142,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection { ...@@ -142,7 +142,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
if(isset($this->reference_field)) if(isset($this->reference_field))
$this->data[$key]->set($this->reference_field,$this->reference); $this->data[$key]->rawSet($this->reference_field,$this->reference);
return $this->data[$key]; return $this->data[$key];
......
...@@ -829,3 +829,5 @@ class Doctrine_DQL_Parser { ...@@ -829,3 +829,5 @@ class Doctrine_DQL_Parser {
} }
?> ?>
...@@ -87,10 +87,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -87,10 +87,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @var integer $oid object identifier * @var integer $oid object identifier
*/ */
private $oid; private $oid;
/**
* @var boolean $loaded whether or not this object has its data loaded from database
*/
private $loaded = false;
/** /**
* constructor * constructor
...@@ -149,8 +145,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -149,8 +145,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if($cols <= 1) if($cols <= 1)
$this->state = Doctrine_Record::STATE_PROXY; $this->state = Doctrine_Record::STATE_PROXY;
else
$this->loaded = true;
$this->prepareIdentifiers(); $this->prepareIdentifiers();
...@@ -177,14 +171,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -177,14 +171,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public function getOID() { public function getOID() {
return $this->oid; return $this->oid;
} }
/**
* isLoaded
* whether or not this object has been fully loaded
* @return boolean
*/
public function isLoaded() {
return $this->loaded;
}
/** /**
* cleanData * cleanData
* modifies data array * modifies data array
...@@ -245,7 +231,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -245,7 +231,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
unset($this->references); unset($this->references);
unset($this->originals); unset($this->originals);
unset($this->oid); unset($this->oid);
unset($this->loaded);
foreach($this->data as $k=>$v) { foreach($this->data as $k=>$v) {
if($v instanceof Doctrine_Record) if($v instanceof Doctrine_Record)
...@@ -273,8 +258,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -273,8 +258,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->table->getRepository()->add($this); $this->table->getRepository()->add($this);
$this->loaded = true;
$this->cleanData(); $this->cleanData();
//unset($this->data['id']); //unset($this->data['id']);
...@@ -335,7 +318,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -335,7 +318,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->prepareIdentifiers(); $this->prepareIdentifiers();
$this->loaded = true;
$this->state = Doctrine_Record::STATE_CLEAN; $this->state = Doctrine_Record::STATE_CLEAN;
return true; return true;
...@@ -360,7 +342,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -360,7 +342,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->state = Doctrine_Record::STATE_CLEAN; $this->state = Doctrine_Record::STATE_CLEAN;
$this->modified = array(); $this->modified = array();
$this->loaded = true;
} }
/** /**
* return the factory that created this data access object * return the factory that created this data access object
...@@ -390,12 +371,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -390,12 +371,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
// check if the property is not loaded (= it is an empty array) // check if the property is not loaded (= it is an empty array)
if(is_array($this->data[$name])) { if(is_array($this->data[$name])) {
if( ! $this->loaded) { // no use trying to load the data from database if the Doctrine_Record is not a proxy
// no use trying to load the data from database if the Doctrine_Record is new or clean
if($this->state != Doctrine_Record::STATE_TDIRTY && if($this->state != Doctrine_Record::STATE_TDIRTY &&
$this->state != Doctrine_Record::STATE_TCLEAN && $this->state != Doctrine_Record::STATE_TCLEAN &&
$this->state != Doctrine_Record::STATE_CLEAN) { $this->state != Doctrine_Record::STATE_CLEAN &&
$this->state != Doctrine_Record::STATE_DIRTY) {
if( ! empty($this->collections)) { if( ! empty($this->collections)) {
foreach($this->collections as $collection) { foreach($this->collections as $collection) {
...@@ -406,12 +386,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -406,12 +386,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
} }
$this->state = Doctrine_Record::STATE_CLEAN; $this->state = Doctrine_Record::STATE_CLEAN;
} }
$this->loaded = true;
}
if(is_array($this->data[$name])) if(is_array($this->data[$name]))
return null; return null;
} }
return $this->data[$name]; return $this->data[$name];
} }
...@@ -438,7 +415,21 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -438,7 +415,21 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if( ! empty($id)) if( ! empty($id))
$value = $id; $value = $id;
if(isset($this->data[$name])) {
if( ! is_array($this->data[$name])) {
if($this->data[$name] !== $value) {
switch($this->state):
case Doctrine_Record::STATE_CLEAN:
$this->state = Doctrine_Record::STATE_DIRTY;
break;
case Doctrine_Record::STATE_TCLEAN:
$this->state = Doctrine_Record::STATE_TDIRTY;
endswitch;
}
}
$this->data[$name] = $value; $this->data[$name] = $value;
$this->modified[] = $name;
}
} }
/** /**
* set * set
...@@ -452,8 +443,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -452,8 +443,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
*/ */
public function set($name,$value) { public function set($name,$value) {
if(isset($this->data[$name])) { if(isset($this->data[$name])) {
$old = $this->get($name);
if($value instanceof Doctrine_Record) { if($value instanceof Doctrine_Record) {
$id = $value->getID(); $id = $value->getID();
...@@ -462,12 +451,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -462,12 +451,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$value = $value->getID(); $value = $value->getID();
} }
$old = $this->get($name);
if($old !== $value) { if($old !== $value) {
$this->data[$name] = $value; $this->data[$name] = $value;
$this->modified[] = $name; $this->modified[] = $name;
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:
......
...@@ -207,3 +207,5 @@ class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase { ...@@ -207,3 +207,5 @@ class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase {
} }
?> ?>
...@@ -2,6 +2,43 @@ ...@@ -2,6 +2,43 @@
require_once("UnitTestCase.class.php"); require_once("UnitTestCase.class.php");
class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
public function testManyToManyTreeStructure() {
$task = $this->session->create("Task");
$task->name = "Task 1";
$task->Resource[0]->name = "Resource 1";
$this->session->flush();
$this->assertEqual($this->dbh->query("SELECT COUNT(*) FROM assignment")->fetch(PDO::FETCH_NUM),array(1));
$task = new Task();
$this->assertTrue($task instanceof Task);
$this->assertEqual($task->getState(), Doctrine_Record::STATE_TCLEAN);
$this->assertTrue($task->Task[0] instanceof Task);
$this->assertEqual($task->Task[0]->getState(), Doctrine_Record::STATE_TCLEAN);
$this->assertTrue($task->Resource[0] instanceof Resource);
$this->assertEqual($task->Resource[0]->getState(), Doctrine_Record::STATE_TCLEAN);
$task->name = "Task 1";
$task->Resource[0]->name = "Resource 1";
$task->Task[0]->name = "Subtask 1";
$this->assertEqual($task->name, "Task 1");
$this->assertEqual($task->Resource[0]->name, "Resource 1");
$this->assertEqual($task->Resource->count(), 1);
$this->assertEqual($task->Task[0]->name, "Subtask 1");
$this->session->flush();
$task = $task->getTable()->find($task->getID());
$this->assertEqual($task->name, "Task 1");
$this->assertEqual($task->Resource[0]->name, "Resource 1");
$this->assertEqual($task->Resource->count(), 1);
$this->assertEqual($task->Task[0]->name, "Subtask 1");
}
public function testOne2OneForeign() { public function testOne2OneForeign() {
......
...@@ -32,7 +32,7 @@ class Doctrine_UnitTestCase extends UnitTestCase { ...@@ -32,7 +32,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
$this->manager->setAttribute(Doctrine::ATTR_CACHE, Doctrine::CACHE_NONE); $this->manager->setAttribute(Doctrine::ATTR_CACHE, Doctrine::CACHE_NONE);
$this->manager->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_IMMEDIATE); $this->manager->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_IMMEDIATE);
$this->tables = array("entity","email","phonenumber","groupuser","album","song","element","error","description","address","account"); $this->tables = array("entity","email","phonenumber","groupuser","album","song","element","error","description","address","account","task","resource","assignment");
$tables = $this->tables; $tables = $this->tables;
......
...@@ -10,7 +10,6 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase { ...@@ -10,7 +10,6 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
$email = $this->old->Email; $email = $this->old->Email;
$email->address = "zYne@invalid"; $email->address = "zYne@invalid";
$this->assertTrue($this->old->isLoaded());
$this->assertTrue($this->old->getModified() == $set); $this->assertTrue($this->old->getModified() == $set);
$validator = new Doctrine_Validator(); $validator = new Doctrine_Validator();
......
...@@ -124,4 +124,31 @@ class Song extends Doctrine_Record { ...@@ -124,4 +124,31 @@ class Song extends Doctrine_Record {
$this->hasColumn("title","string",30); $this->hasColumn("title","string",30);
} }
} }
class Task extends Doctrine_Record {
public function setUp() {
$this->hasMany("Resource","Assignment.resource_id");
$this->hasMany("Task","Task.parent_id");
}
public function setTableDefinition() {
$this->hasColumn("name","string",100);
$this->hasColumn("parent_id","integer");
}
}
class Resource extends Doctrine_Record {
public function setUp() {
$this->hasMany("Task","Assignment.task_id");
}
public function setTableDefinition() {
$this->hasColumn("name","string",100);
}
}
class Assignment extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("task_id","integer");
$this->hasColumn("resource_id","integer");
}
}
?> ?>
...@@ -24,13 +24,17 @@ error_reporting(E_ALL); ...@@ -24,13 +24,17 @@ error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests"); $test = new GroupTest("Doctrine Framework Unit Tests");
$test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_SessionTestCase());
$test->addTestCase(new Doctrine_RecordTestCase()); $test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_TableTestCase());
$test->addTestCase(new Doctrine_SessionTestCase());
$test->addTestCase(new Doctrine_DQL_ParserTestCase());
$test->addTestCase(new Doctrine_ValidatorTestCase()); $test->addTestCase(new Doctrine_ValidatorTestCase());
$test->addTestCase(new Doctrine_ManagerTestCase()); $test->addTestCase(new Doctrine_ManagerTestCase());
...@@ -44,7 +48,7 @@ $test->addTestCase(new Doctrine_EventListenerTestCase()); ...@@ -44,7 +48,7 @@ $test->addTestCase(new Doctrine_EventListenerTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase()); $test->addTestCase(new Doctrine_BatchIteratorTestCase());
$test->addTestCase(new Doctrine_DQL_ParserTestCase());
$test->addTestCase(new Doctrine_ConfigurableTestCase()); $test->addTestCase(new Doctrine_ConfigurableTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment