Commit 7b84d155 authored by zYne's avatar zYne

Fixes #126, #127

Ticket: 126
parent c5747109
......@@ -252,9 +252,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
foreach($this->getNormalIterator() as $record) {
if($value !== null) {
$record->rawSet($this->reference_field, $value);
$record->set($this->reference_field, $value, false);
} else {
$record->rawSet($this->reference_field, $this->reference);
$record->set($this->reference_field, $this->reference, false);
}
}
} elseif($relation instanceof Doctrine_Association) {
......@@ -360,7 +360,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
if( ! isset($offset)) {
foreach($coll as $record) {
if(isset($this->reference_field))
$record->rawSet($this->reference_field,$this->reference);
$record->set($this->reference_field,$this->reference, false);
$this->reference->addReference($record, $this->relation);
}
......@@ -431,10 +431,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$value = $this->reference->get($this->relation->getLocal());
if($value !== null) {
$this->data[$key]->rawSet($this->reference_field, $value);
$this->data[$key]->set($this->reference_field, $value, false);
} else {
$this->data[$key]->rawSet($this->reference_field, $this->reference);
$this->data[$key]->set($this->reference_field, $this->reference, false);
}
}
}
......@@ -483,7 +483,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public function set($key,Doctrine_Record $record) {
if(isset($this->reference_field))
$record->rawSet($this->reference_field,$this->reference);
$record->set($this->reference_field, $this->reference, false);
$this->data[$key] = $record;
}
......@@ -498,7 +498,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return false;
if(isset($this->reference_field))
$record->internalSet($this->reference_field,$this->reference);
$record->set($this->reference_field, $this->reference, false);
if(isset($key)) {
if(isset($this->data[$key]))
......@@ -527,7 +527,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public function add(Doctrine_Record $record,$key = null) {
if(isset($this->reference_field))
$record->rawSet($this->reference_field,$this->reference);
$record->set($this->reference_field, $this->reference, false);
if(in_array($record,$this->data)) {
return false;
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine::autoload('Doctrine_Collection');
/**
* Doctrine_Collection_Batch a collection of records,
......@@ -148,7 +167,7 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
if(isset($this->reference_field))
$this->data[$key]->rawSet($this->reference_field,$this->reference);
$this->data[$key]->set($this->reference_field, $this->reference, false);
return $this->data[$key];
......
......@@ -414,7 +414,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
case Doctrine_Relation::ONE_AGGREGATE:
// one-to-one relation
$last->rawSet($fk->getLocal(), $record->getIncremented());
if($fk instanceof Doctrine_LocalKey)
$last->set($fk->getLocal(), $record->getIncremented(), false);
$last->initSingleReference($record, $fk);
......
......@@ -682,72 +682,22 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
return $this->references[$name];
}
/**
* internalSet
*
* @param mixed $name
* @param mixed $value
*/
final public function internalSet($name, $value) {
if($value === null)
$value = self::$null;
$this->data[$name] = $value;
}
/**
* rawSet
* doctrine uses this function internally, not recommended for developers
*
* rawSet() works in very same same way as set() with an exception that
* 1. it cannot be used for setting references
* 2. it cannot load uninitialized fields
*
* @param mixed $name name of the property or reference
* @param mixed $value value of the property or reference
*/
final public function rawSet($name,$value) {
$name = strtolower($name);
if($value instanceof Doctrine_Record)
$id = $value->getIncremented();
if(isset($id))
$value = $id;
if(isset($this->data[$name])) {
if($this->data[$name] === self::$null) {
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;
}
}
if($this->state == Doctrine_Record::STATE_TCLEAN)
$this->state = Doctrine_Record::STATE_TDIRTY;
if($value === null)
$value = self::$null;
$this->data[$name] = $value;
$this->modified[] = $name;
}
}
/**
* set
* method for altering properties and Doctrine_Record references
* if the load parameter is set to false this method will not try to load uninitialized record data
*
* @param mixed $name name of the property or reference
* @param mixed $value value of the property or reference
* @param boolean $load whether or not to refresh / load the uninitialized record data
*
* @throws Doctrine_Record_Exception if trying to set a value for unknown property / related component
* @throws Doctrine_Record_Exception if trying to set a value of wrong type for related component
*
* @return Doctrine_Record
*/
public function set($name,$value) {
public function set($name, $value, $load = true) {
$lower = strtolower($name);
if(isset($this->data[$lower])) {
......@@ -759,7 +709,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$value = $id;
}
$old = $this->get($lower, false);
if($load)
$old = $this->get($lower, false);
else
$old = $this->data[$lower];
if($old !== $value) {
......@@ -773,7 +726,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->modified[] = $lower;
switch($this->state):
case Doctrine_Record::STATE_CLEAN:
case Doctrine_Record::STATE_PROXY:
$this->state = Doctrine_Record::STATE_DIRTY;
break;
case Doctrine_Record::STATE_TCLEAN:
......@@ -947,7 +899,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
return $a;
}
/**
* count
* this class implements countable interface
*
* @return integer the number of columns
*/
public function count() {
......@@ -955,13 +909,15 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
/**
* alias for count()
*
* @return integer
*/
public function getColumnCount() {
return $this->count();
}
/**
* toArray
* returns record as an array
* returns the record as an array
*
* @return array
*/
......@@ -978,7 +934,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
return $a;
}
/**
* checks if record has data
* exists
* returns true if this record is persistent, otherwise false
*
* @return boolean
*/
public function exists() {
......@@ -1475,13 +1433,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* merges this record with an array of values
*
* @param array $values
* @return void
*/
public function merge(array $values) {
foreach($this->table->getColumnNames() as $value) {
try {
if(isset($values[$value]))
$this->set($value, $values[$value]);
} catch(Exception $e) { }
} catch(Exception $e) {
// silence all exceptions
}
}
}
/**
......
......@@ -95,6 +95,7 @@ $test->addTestCase(new Doctrine_EventListener_Chain_TestCase());
$test->addTestCase(new Doctrine_DataDict_Sqlite_TestCase());
$test->addTestCase(new Doctrine_BooleanTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
......
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