fixes #688
This commit is contained in:
parent
1f18a99fd1
commit
02c57f5977
@ -718,7 +718,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* synchronizeWithArray
|
* synchronizeFromArray
|
||||||
* synchronizes a Doctrine_Collection with data from an array
|
* synchronizes a Doctrine_Collection with data from an array
|
||||||
*
|
*
|
||||||
* it expects an array representation of a Doctrine_Collection similar to the return
|
* it expects an array representation of a Doctrine_Collection similar to the return
|
||||||
@ -727,17 +727,18 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
*
|
*
|
||||||
* @param array $array representation of a Doctrine_Collection
|
* @param array $array representation of a Doctrine_Collection
|
||||||
*/
|
*/
|
||||||
public function synchronizeWithArray(array $array)
|
public function synchronizeFromArray(array $array)
|
||||||
{
|
{
|
||||||
foreach ($this as $key => $record) {
|
foreach ($this as $key => $record) {
|
||||||
if (isset($array[$key])) {
|
if (isset($array[$key])) {
|
||||||
$record->synchronizeWithArray($array[$key]);
|
$record->synchronizeFromArray($array[$key]);
|
||||||
unset($array[$key]);
|
unset($array[$key]);
|
||||||
} else {
|
} else {
|
||||||
// remove records that don't exist in the array
|
// remove records that don't exist in the array
|
||||||
$this->remove($key);
|
$this->remove($key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create new records for each new row in the array
|
// create new records for each new row in the array
|
||||||
foreach ($array as $rowKey => $row) {
|
foreach ($array as $rowKey => $row) {
|
||||||
$this[$rowKey]->fromArray($row);
|
$this[$rowKey]->fromArray($row);
|
||||||
|
@ -1324,8 +1324,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
|
|||||||
{
|
{
|
||||||
foreach ($array as $key => $value) {
|
foreach ($array as $key => $value) {
|
||||||
if ($this->getTable()->hasRelation($key)) {
|
if ($this->getTable()->hasRelation($key)) {
|
||||||
$this->get($key)->synchronizeWithArray($value);
|
$this->get($key)->synchronizeFromArray($value);
|
||||||
} else if ($this->getTable()->hasField($key)) {
|
} else if ($this->getTable()->hasColumn($key)) {
|
||||||
$this->set($key, $value);
|
$this->set($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,9 +211,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
|
|||||||
*/
|
*/
|
||||||
public function ownsOne()
|
public function ownsOne()
|
||||||
{
|
{
|
||||||
$this->_table->bind(func_get_args(), Doctrine_Relation::ONE_COMPOSITE);
|
throw new Doctrine_Exception('ownsMany() has been deprecated.');
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,8 +227,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
|
|||||||
*/
|
*/
|
||||||
public function ownsMany()
|
public function ownsMany()
|
||||||
{
|
{
|
||||||
$this->_table->bind(func_get_args(), Doctrine_Relation::MANY_COMPOSITE);
|
throw new Doctrine_Exception('ownsOne() has been deprecated.');
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,9 +3,9 @@ class Entity extends Doctrine_Record
|
|||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->ownsOne('Email', array('local' => 'email_id'));
|
$this->hasOne('Email', array('local' => 'email_id'));
|
||||||
$this->hasMany('Phonenumber', array('local' => 'id', 'foreign' => 'entity_id'));
|
$this->hasMany('Phonenumber', array('local' => 'id', 'foreign' => 'entity_id'));
|
||||||
$this->ownsOne('Account', array('foreign' => 'entity_id'));
|
$this->hasOne('Account', array('foreign' => 'entity_id'));
|
||||||
$this->hasMany('Entity', array('local' => 'entity1',
|
$this->hasMany('Entity', array('local' => 'entity1',
|
||||||
'refClass' => 'EntityReference',
|
'refClass' => 'EntityReference',
|
||||||
'foreign' => 'entity2',
|
'foreign' => 'entity2',
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
class Error extends Doctrine_Record {
|
class Error extends Doctrine_Record {
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->ownsMany('Description', 'Description.file_md5', 'file_md5');
|
$this->hasMany('Description', 'Description.file_md5', 'file_md5');
|
||||||
}
|
}
|
||||||
public function setTableDefinition() {
|
public function setTableDefinition() {
|
||||||
$this->hasColumn('message', 'string',200);
|
$this->hasColumn('message', 'string',200);
|
||||||
|
@ -4,6 +4,6 @@ class FilterTest extends Doctrine_Record {
|
|||||||
$this->hasColumn('name', 'string',100);
|
$this->hasColumn('name', 'string',100);
|
||||||
}
|
}
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->ownsMany('FilterTest2 as filtered', 'FilterTest2.test1_id');
|
$this->hasMany('FilterTest2 as filtered', 'FilterTest2.test1_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ class Package extends Doctrine_Record {
|
|||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->ownsMany('PackageVersion as Version', 'PackageVersion.package_id');
|
$this->hasMany('PackageVersion as Version', 'PackageVersion.package_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,6 @@ class QueryTest_Board extends Doctrine_Record
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->hasOne('QueryTest_Category as category', 'QueryTest_Board.categoryId');
|
$this->hasOne('QueryTest_Category as category', 'QueryTest_Board.categoryId');
|
||||||
$this->ownsOne('QueryTest_Entry as lastEntry', 'QueryTest_Board.lastEntryId');
|
$this->hasOne('QueryTest_Entry as lastEntry', 'QueryTest_Board.lastEntryId');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ class QueryTest_Category extends Doctrine_Record
|
|||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->ownsMany('QueryTest_Category as subCategories', 'subCategories.parentCategoryId');
|
$this->hasMany('QueryTest_Category as subCategories', 'subCategories.parentCategoryId');
|
||||||
$this->hasOne('QueryTest_Category as rootCategory', 'QueryTest_Category.rootCategoryId');
|
$this->hasOne('QueryTest_Category as rootCategory', 'QueryTest_Category.rootCategoryId');
|
||||||
$this->ownsMany('QueryTest_Board as boards', 'QueryTest_Board.categoryId');
|
$this->hasMany('QueryTest_Board as boards', 'QueryTest_Board.categoryId');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class Rec1 extends Doctrine_Record
|
|||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->ownsOne('Rec2 as Account', array('local' => 'id', 'foreign' => 'user_id'));
|
$this->hasOne('Rec2 as Account', array('local' => 'id', 'foreign' => 'user_id'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ class Rec2 extends Doctrine_Record
|
|||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->ownsOne('Rec1 as User', 'Rec2.user_id');
|
$this->hasOne('Rec1 as User', 'Rec2.user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ class ValidatorTest_Person extends Doctrine_Record {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->ownsOne('ValidatorTest_FootballPlayer', 'ValidatorTest_FootballPlayer.person_id');
|
$this->hasOne('ValidatorTest_FootballPlayer', 'ValidatorTest_FootballPlayer.person_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,13 +60,13 @@ class Doctrine_Record_Synchronize_TestCase extends Doctrine_UnitTestCase
|
|||||||
// delete a Phonenumber
|
// delete a Phonenumber
|
||||||
array_pop($userArray['Phonenumber']);
|
array_pop($userArray['Phonenumber']);
|
||||||
|
|
||||||
$user->synchronizeWithArray($userArray);
|
$user->synchronizeFromArray($userArray);
|
||||||
$this->assertEqual($user->Phonenumber->count(), 1);
|
$this->assertEqual($user->Phonenumber->count(), 1);
|
||||||
$this->assertEqual($user->Phonenumber[0]->phonenumber, '555 321');
|
$this->assertEqual($user->Phonenumber[0]->phonenumber, '555 321');
|
||||||
|
|
||||||
// change Email
|
// change Email
|
||||||
$userArray['Email']['address'] = 'johndow@mail.com';
|
$userArray['Email']['address'] = 'johndow@mail.com';
|
||||||
$user->synchronizeWithArray($userArray);
|
$user->synchronizeFromArray($userArray);
|
||||||
$this->assertEqual($user->Email->address, 'johndow@mail.com');
|
$this->assertEqual($user->Email->address, 'johndow@mail.com');
|
||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
@ -86,7 +86,7 @@ class Doctrine_Record_Synchronize_TestCase extends Doctrine_UnitTestCase
|
|||||||
$userArray = $user->toArray(true);
|
$userArray = $user->toArray(true);
|
||||||
$userArray['Phonenumber'][] = array('phonenumber' => '333 238');
|
$userArray['Phonenumber'][] = array('phonenumber' => '333 238');
|
||||||
|
|
||||||
$user->synchronizeWithArray($userArray);
|
$user->synchronizeFromArray($userArray);
|
||||||
$this->assertEqual($user->Phonenumber->count(), 2);
|
$this->assertEqual($user->Phonenumber->count(), 2);
|
||||||
$this->assertEqual($user->Phonenumber[1]->phonenumber, '333 238');
|
$this->assertEqual($user->Phonenumber[1]->phonenumber, '333 238');
|
||||||
$user->save();
|
$user->save();
|
||||||
@ -106,7 +106,7 @@ class Doctrine_Record_Synchronize_TestCase extends Doctrine_UnitTestCase
|
|||||||
unset($userArray['Phonenumber']);
|
unset($userArray['Phonenumber']);
|
||||||
unset($userArray['Email']);
|
unset($userArray['Email']);
|
||||||
|
|
||||||
$user->synchronizeWithArray($userArray);
|
$user->synchronizeFromArray($userArray);
|
||||||
$this->assertEqual($user->Phonenumber->count(), 0);
|
$this->assertEqual($user->Phonenumber->count(), 0);
|
||||||
$this->assertTrue(!isset($user->Email));
|
$this->assertTrue(!isset($user->Email));
|
||||||
$user->save();
|
$user->save();
|
||||||
|
@ -106,7 +106,7 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
|
|||||||
$fk = $this->objTable->getTable()->getRelation("Email");
|
$fk = $this->objTable->getTable()->getRelation("Email");
|
||||||
$this->assertTrue($fk instanceof Doctrine_Relation_LocalKey);
|
$this->assertTrue($fk instanceof Doctrine_Relation_LocalKey);
|
||||||
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
|
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
|
||||||
$this->assertTrue($fk->getType() == Doctrine_Relation::ONE_COMPOSITE);
|
$this->assertTrue($fk->getType() == Doctrine_Relation::ONE_AGGREGATE);
|
||||||
$this->assertTrue($fk->getLocal() == "email_id");
|
$this->assertTrue($fk->getLocal() == "email_id");
|
||||||
$this->assertTrue($fk->getForeign() == $fk->getTable()->getIdentifier());
|
$this->assertTrue($fk->getForeign() == $fk->getTable()->getIdentifier());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user