Doctrine_Table::find now returns false if record is not found (instead of throwing InvalidKeyException)
This commit is contained in:
parent
184a7f621d
commit
d1ed73c6d9
@ -13,11 +13,14 @@ abstract class Doctrine_Access implements ArrayAccess {
|
||||
/**
|
||||
* setArray
|
||||
* @param array $array an array of key => value pairs
|
||||
* @return Doctrine_Access
|
||||
*/
|
||||
public function setArray(array $array) {
|
||||
foreach($array as $k=>$v):
|
||||
$this->set($k,$v);
|
||||
endforeach;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* __set -- an alias of set()
|
||||
@ -72,11 +75,7 @@ abstract class Doctrine_Access implements ArrayAccess {
|
||||
* @param mixed $offset
|
||||
*/
|
||||
public function offsetUnset($offset) {
|
||||
if($this instanceof Doctrine_Collection) {
|
||||
return $this->remove($offset);
|
||||
} else {
|
||||
$this->set($offset,null);
|
||||
}
|
||||
return $this->remove($offset);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -21,15 +21,15 @@ class Doctrine_Cache_Sqlite {
|
||||
*/
|
||||
const DELETE = "DELETE FROM %s WHERE id %s";
|
||||
/**
|
||||
* @var Doctrine_Table $table
|
||||
* @var Doctrine_Table $table the table object this cache container belongs to
|
||||
*/
|
||||
private $table;
|
||||
/**
|
||||
* @var PDO $dbh
|
||||
* @var PDO $dbh database handler
|
||||
*/
|
||||
private $dbh;
|
||||
/**
|
||||
* @var array $fetched an array of fetched primary keys
|
||||
* @var array $fetched an array of fetched primary keys
|
||||
*/
|
||||
private $fetched = array();
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Doctrine_Null
|
||||
*
|
||||
* Simple empty class representing a null value
|
||||
* used for extra fast null value testing with isset() rather than array_key_exists()
|
||||
*/
|
||||
class Doctrine_Null { }
|
||||
?>
|
||||
|
@ -1042,12 +1042,16 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
$this->references[$name] = $table->create();
|
||||
$this->set($fk->getLocal(),$this->references[$name]);
|
||||
} else {
|
||||
try {
|
||||
$this->references[$name] = $table->find($id);
|
||||
} catch(Doctrine_Find_Exception $e) {
|
||||
|
||||
$record = $table->find($id);
|
||||
|
||||
if($record !== false)
|
||||
$this->references[$name] = $record;
|
||||
else
|
||||
$this->references[$name] = $table->create();
|
||||
|
||||
//$this->set($fk->getLocal(),$this->references[$name]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} elseif ($fk instanceof Doctrine_ForeignKey) {
|
||||
|
@ -33,7 +33,7 @@ class Doctrine_Record_Iterator extends ArrayIterator {
|
||||
public function current() {
|
||||
$value = parent::current();
|
||||
|
||||
if($value == self::$null)
|
||||
if($value === self::$null)
|
||||
return null;
|
||||
else
|
||||
return $value;
|
||||
|
@ -648,7 +648,7 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
$this->data = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if($this->data === false)
|
||||
throw new Doctrine_Find_Exception();
|
||||
return false;
|
||||
}
|
||||
return $this->getRecord();
|
||||
}
|
||||
@ -827,7 +827,7 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
*/
|
||||
public function getTypeOf($column) {
|
||||
if(isset($this->columns[$column]))
|
||||
return $this->columns[$column][0];
|
||||
return $this->columns[$column][0];
|
||||
}
|
||||
/**
|
||||
* setData
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.class.php");
|
||||
require_once("UnitTestCase.php");
|
||||
|
||||
class Doctrine_BatchIteratorTestCase extends Doctrine_UnitTestCase {
|
||||
public function testIterator() {
|
||||
$graph = new Doctrine_Query($this->session);
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.class.php");
|
||||
require_once("UnitTestCase.php");
|
||||
|
||||
class Doctrine_Cache_FileTestCase extends Doctrine_UnitTestCase {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.class.php");
|
||||
require_once("UnitTestCase.php");
|
||||
|
||||
class Doctrine_Cache_SqliteTestCase extends Doctrine_UnitTestCase {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.class.php");
|
||||
require_once("UnitTestCase.php");
|
||||
|
||||
class Doctrine_ConfigurableTestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareTables() { }
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.class.php");
|
||||
require_once("UnitTestCase.php");
|
||||
|
||||
class Doctrine_EventListenerTestCase extends Doctrine_UnitTestCase {
|
||||
public function testEvents() {
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.class.php");
|
||||
require_once("UnitTestCase.php");
|
||||
class Doctrine_ManagerTestCase extends Doctrine_UnitTestCase {
|
||||
public function testGetInstance() {
|
||||
$this->assertTrue(Doctrine_Manager::getInstance() instanceOf Doctrine_Manager);
|
@ -56,17 +56,22 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
$entries[0]->Log_Status->delete();
|
||||
$this->assertEqual($entries[0]->Log_Status, $entries[1]->Log_Status);
|
||||
$this->assertEqual($entries[0]->Log_Status->getState(), Doctrine_Record::STATE_TCLEAN);
|
||||
|
||||
|
||||
// clear the identity maps
|
||||
|
||||
$entries[0]->Log_Status->getTable()->clear();
|
||||
$entries[0]->getTable()->clear();
|
||||
|
||||
|
||||
$entries = $this->session->query("FROM Log_Entry-I.Log_Status-i");
|
||||
$this->assertEqual($entries->count(), 2);
|
||||
|
||||
$this->assertTrue($entries[0]->Log_Status instanceof Log_Status);
|
||||
|
||||
$this->assertEqual($entries[0]->Log_Status->name, null);
|
||||
$this->assertEqual($entries[1]->Log_Status->name, null);
|
||||
|
||||
}
|
||||
|
||||
public function testOneToOneRelationFetchingWithCustomTableNames() {
|
||||
$entry = new ORM_TestEntry();
|
||||
$entry->name = 'entry 1';
|
||||
@ -687,5 +692,6 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
//$this->assertTrue(isset($values['max']));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.class.php");
|
||||
require_once("UnitTestCase.php");
|
||||
|
||||
class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
|
||||
public function testSerialize() {
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.class.php");
|
||||
require_once("UnitTestCase.php");
|
||||
class Doctrine_SessionTestCase extends Doctrine_UnitTestCase {
|
||||
|
||||
public function testBuildFlushTree() {
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
require_once("UnitTestCase.class.php");
|
||||
require_once("UnitTestCase.php");
|
||||
class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
|
||||
public function testBind() {
|
||||
$table = $this->session->getTable("User");
|
@ -1,30 +1,27 @@
|
||||
<?php
|
||||
ob_start();
|
||||
|
||||
require_once("ConfigurableTestCase.class.php");
|
||||
require_once("ManagerTestCase.class.php");
|
||||
require_once("SessionTestCase.class.php");
|
||||
require_once("TableTestCase.class.php");
|
||||
require_once("EventListenerTestCase.class.php");
|
||||
require_once("BatchIteratorTestCase.class.php");
|
||||
require_once("CacheFileTestCase.class.php");
|
||||
require_once("RecordTestCase.class.php");
|
||||
require_once("AccessTestCase.class.php");
|
||||
require_once("ValidatorTestCase.class.php");
|
||||
require_once("CollectionTestCase.class.php");
|
||||
require_once("ConfigurableTestCase.php");
|
||||
require_once("ManagerTestCase.php");
|
||||
require_once("SessionTestCase.php");
|
||||
require_once("TableTestCase.php");
|
||||
require_once("EventListenerTestCase.php");
|
||||
require_once("BatchIteratorTestCase.php");
|
||||
require_once("CacheFileTestCase.php");
|
||||
require_once("RecordTestCase.php");
|
||||
require_once("AccessTestCase.php");
|
||||
require_once("ValidatorTestCase.php");
|
||||
require_once("CollectionTestCase.php");
|
||||
|
||||
require_once("CacheSqliteTestCase.class.php");
|
||||
require_once("CollectionOffsetTestCase.class.php");
|
||||
require_once("SenseiTestCase.class.php");
|
||||
require_once("QueryTestCase.class.php");
|
||||
require_once("CacheSqliteTestCase.php");
|
||||
require_once("CollectionOffsetTestCase.php");
|
||||
require_once("SenseiTestCase.php");
|
||||
require_once("QueryTestCase.php");
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$test = new GroupTest("Doctrine Framework Unit Tests");
|
||||
|
||||
//$test->addTestCase(new Sensei_UnitTestCase());
|
||||
|
||||
|
||||
$test->addTestCase(new Doctrine_RecordTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_SessionTestCase());
|
||||
|
Loading…
x
Reference in New Issue
Block a user