Commit 02c57f59 authored by jwage's avatar jwage

fixes #688

parent 1f18a99f
......@@ -718,7 +718,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
/**
* synchronizeWithArray
* synchronizeFromArray
* synchronizes a Doctrine_Collection with data from an array
*
* 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
*/
public function synchronizeWithArray(array $array)
public function synchronizeFromArray(array $array)
{
foreach ($this as $key => $record) {
if (isset($array[$key])) {
$record->synchronizeWithArray($array[$key]);
$record->synchronizeFromArray($array[$key]);
unset($array[$key]);
} else {
// remove records that don't exist in the array
$this->remove($key);
}
}
// create new records for each new row in the array
foreach ($array as $rowKey => $row) {
$this[$rowKey]->fromArray($row);
......
......@@ -1324,8 +1324,8 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count
{
foreach ($array as $key => $value) {
if ($this->getTable()->hasRelation($key)) {
$this->get($key)->synchronizeWithArray($value);
} else if ($this->getTable()->hasField($key)) {
$this->get($key)->synchronizeFromArray($value);
} else if ($this->getTable()->hasColumn($key)) {
$this->set($key, $value);
}
}
......
......@@ -211,9 +211,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
*/
public function ownsOne()
{
$this->_table->bind(func_get_args(), Doctrine_Relation::ONE_COMPOSITE);
return $this;
throw new Doctrine_Exception('ownsMany() has been deprecated.');
}
/**
......@@ -229,8 +227,7 @@ abstract class Doctrine_Record_Abstract extends Doctrine_Access
*/
public function ownsMany()
{
$this->_table->bind(func_get_args(), Doctrine_Relation::MANY_COMPOSITE);
return $this;
throw new Doctrine_Exception('ownsOne() has been deprecated.');
}
/**
......
......@@ -3,9 +3,9 @@ class Entity extends Doctrine_Record
{
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->ownsOne('Account', array('foreign' => 'entity_id'));
$this->hasOne('Account', array('foreign' => 'entity_id'));
$this->hasMany('Entity', array('local' => 'entity1',
'refClass' => 'EntityReference',
'foreign' => 'entity2',
......
<?php
class Error extends Doctrine_Record {
public function setUp() {
$this->ownsMany('Description', 'Description.file_md5', 'file_md5');
$this->hasMany('Description', 'Description.file_md5', 'file_md5');
}
public function setTableDefinition() {
$this->hasColumn('message', 'string',200);
......
......@@ -4,6 +4,6 @@ class FilterTest extends Doctrine_Record {
$this->hasColumn('name', 'string',100);
}
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()
{
$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()
{
$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()
{
$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->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()
{
$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()
{
$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() {
$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
array_pop($userArray['Phonenumber']);
$user->synchronizeWithArray($userArray);
$user->synchronizeFromArray($userArray);
$this->assertEqual($user->Phonenumber->count(), 1);
$this->assertEqual($user->Phonenumber[0]->phonenumber, '555 321');
// change Email
$userArray['Email']['address'] = 'johndow@mail.com';
$user->synchronizeWithArray($userArray);
$user->synchronizeFromArray($userArray);
$this->assertEqual($user->Email->address, 'johndow@mail.com');
$user->save();
......@@ -86,7 +86,7 @@ class Doctrine_Record_Synchronize_TestCase extends Doctrine_UnitTestCase
$userArray = $user->toArray(true);
$userArray['Phonenumber'][] = array('phonenumber' => '333 238');
$user->synchronizeWithArray($userArray);
$user->synchronizeFromArray($userArray);
$this->assertEqual($user->Phonenumber->count(), 2);
$this->assertEqual($user->Phonenumber[1]->phonenumber, '333 238');
$user->save();
......@@ -106,7 +106,7 @@ class Doctrine_Record_Synchronize_TestCase extends Doctrine_UnitTestCase
unset($userArray['Phonenumber']);
unset($userArray['Email']);
$user->synchronizeWithArray($userArray);
$user->synchronizeFromArray($userArray);
$this->assertEqual($user->Phonenumber->count(), 0);
$this->assertTrue(!isset($user->Email));
$user->save();
......
......@@ -106,7 +106,7 @@ class Doctrine_Table_TestCase extends Doctrine_UnitTestCase
$fk = $this->objTable->getTable()->getRelation("Email");
$this->assertTrue($fk instanceof Doctrine_Relation_LocalKey);
$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->getForeign() == $fk->getTable()->getIdentifier());
......
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