This commit is contained in:
parent
ff9c9d84a9
commit
bafcd6625c
@ -119,9 +119,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
|
||||
foreach($this->getNormalIterator() as $record) {
|
||||
if($value !== null) {
|
||||
$record->set($this->reference_field, $value);
|
||||
$record->rawSet($this->reference_field, $value);
|
||||
} 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
|
||||
$value = $this->reference->get($this->relation->getLocal());
|
||||
|
||||
if($value !== null) {
|
||||
$this->data[$key]->set($this->reference_field, $value);
|
||||
$this->data[$key]->rawSet($this->reference_field, $value);
|
||||
} 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 {
|
||||
|
||||
|
||||
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];
|
||||
|
@ -829,3 +829,5 @@ class Doctrine_DQL_Parser {
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
@ -87,10 +87,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
* @var integer $oid object identifier
|
||||
*/
|
||||
private $oid;
|
||||
/**
|
||||
* @var boolean $loaded whether or not this object has its data loaded from database
|
||||
*/
|
||||
private $loaded = false;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
@ -149,8 +145,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
if($cols <= 1)
|
||||
$this->state = Doctrine_Record::STATE_PROXY;
|
||||
else
|
||||
$this->loaded = true;
|
||||
|
||||
$this->prepareIdentifiers();
|
||||
|
||||
@ -177,14 +171,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
public function getOID() {
|
||||
return $this->oid;
|
||||
}
|
||||
/**
|
||||
* isLoaded
|
||||
* whether or not this object has been fully loaded
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLoaded() {
|
||||
return $this->loaded;
|
||||
}
|
||||
/**
|
||||
* cleanData
|
||||
* modifies data array
|
||||
@ -245,7 +231,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
unset($this->references);
|
||||
unset($this->originals);
|
||||
unset($this->oid);
|
||||
unset($this->loaded);
|
||||
|
||||
foreach($this->data as $k=>$v) {
|
||||
if($v instanceof Doctrine_Record)
|
||||
@ -273,8 +258,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->table->getRepository()->add($this);
|
||||
|
||||
$this->loaded = true;
|
||||
|
||||
$this->cleanData();
|
||||
|
||||
//unset($this->data['id']);
|
||||
@ -335,7 +318,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->prepareIdentifiers();
|
||||
|
||||
$this->loaded = true;
|
||||
$this->state = Doctrine_Record::STATE_CLEAN;
|
||||
|
||||
return true;
|
||||
@ -360,7 +342,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
$this->state = Doctrine_Record::STATE_CLEAN;
|
||||
$this->modified = array();
|
||||
$this->loaded = true;
|
||||
}
|
||||
/**
|
||||
* return the factory that created this data access object
|
||||
@ -389,29 +370,25 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
// check if the property is not loaded (= it is an empty array)
|
||||
if(is_array($this->data[$name])) {
|
||||
|
||||
if( ! $this->loaded) {
|
||||
|
||||
// no use trying to load the data from database if the Doctrine_Record is new or clean
|
||||
if($this->state != Doctrine_Record::STATE_TDIRTY &&
|
||||
$this->state != Doctrine_Record::STATE_TCLEAN &&
|
||||
$this->state != Doctrine_Record::STATE_CLEAN) {
|
||||
|
||||
if( ! empty($this->collections)) {
|
||||
foreach($this->collections as $collection) {
|
||||
$collection->load($this);
|
||||
}
|
||||
} else {
|
||||
$this->refresh();
|
||||
// no use trying to load the data from database if the Doctrine_Record is not a proxy
|
||||
if($this->state != Doctrine_Record::STATE_TDIRTY &&
|
||||
$this->state != Doctrine_Record::STATE_TCLEAN &&
|
||||
$this->state != Doctrine_Record::STATE_CLEAN &&
|
||||
$this->state != Doctrine_Record::STATE_DIRTY) {
|
||||
|
||||
if( ! empty($this->collections)) {
|
||||
foreach($this->collections as $collection) {
|
||||
$collection->load($this);
|
||||
}
|
||||
$this->state = Doctrine_Record::STATE_CLEAN;
|
||||
} else {
|
||||
$this->refresh();
|
||||
}
|
||||
$this->loaded = true;
|
||||
$this->state = Doctrine_Record::STATE_CLEAN;
|
||||
}
|
||||
|
||||
|
||||
if(is_array($this->data[$name]))
|
||||
return null;
|
||||
|
||||
}
|
||||
return $this->data[$name];
|
||||
}
|
||||
@ -437,8 +414,22 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
|
||||
if( ! empty($id))
|
||||
$value = $id;
|
||||
|
||||
$this->data[$name] = $value;
|
||||
|
||||
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->modified[] = $name;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* set
|
||||
@ -452,8 +443,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
*/
|
||||
public function set($name,$value) {
|
||||
if(isset($this->data[$name])) {
|
||||
$old = $this->get($name);
|
||||
|
||||
|
||||
if($value instanceof Doctrine_Record) {
|
||||
$id = $value->getID();
|
||||
@ -461,13 +450,12 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
if( ! empty($id))
|
||||
$value = $value->getID();
|
||||
}
|
||||
|
||||
$old = $this->get($name);
|
||||
|
||||
if($old !== $value) {
|
||||
$this->data[$name] = $value;
|
||||
|
||||
$this->modified[] = $name;
|
||||
|
||||
|
||||
switch($this->state):
|
||||
case Doctrine_Record::STATE_CLEAN:
|
||||
case Doctrine_Record::STATE_PROXY:
|
||||
|
@ -207,3 +207,5 @@ class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
@ -2,6 +2,43 @@
|
||||
require_once("UnitTestCase.class.php");
|
||||
|
||||
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() {
|
||||
|
||||
|
@ -32,7 +32,7 @@ class Doctrine_UnitTestCase extends UnitTestCase {
|
||||
$this->manager->setAttribute(Doctrine::ATTR_CACHE, Doctrine::CACHE_NONE);
|
||||
$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;
|
||||
|
||||
|
||||
|
@ -10,7 +10,6 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
|
||||
$email = $this->old->Email;
|
||||
$email->address = "zYne@invalid";
|
||||
|
||||
$this->assertTrue($this->old->isLoaded());
|
||||
$this->assertTrue($this->old->getModified() == $set);
|
||||
|
||||
$validator = new Doctrine_Validator();
|
||||
|
@ -124,4 +124,31 @@ class Song extends Doctrine_Record {
|
||||
$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,12 +24,16 @@ error_reporting(E_ALL);
|
||||
$test = new GroupTest("Doctrine Framework Unit Tests");
|
||||
|
||||
|
||||
$test->addTestCase(new Doctrine_TableTestCase());
|
||||
|
||||
|
||||
|
||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_TableTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_SessionTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||
$test->addTestCase(new Doctrine_DQL_ParserTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_ValidatorTestCase());
|
||||
|
||||
@ -44,7 +48,7 @@ $test->addTestCase(new Doctrine_EventListenerTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_BatchIteratorTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_DQL_ParserTestCase());
|
||||
|
||||
|
||||
$test->addTestCase(new Doctrine_ConfigurableTestCase());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user