This commit is contained in:
parent
1a76029f9e
commit
1133b26c2b
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Doctrine_Record_Lock_TestCase extends Doctrine_UnitTestCase {
|
||||
public function prepareTables()
|
||||
public function prepareTables()
|
||||
{
|
||||
$this->tables[] = 'rec1';
|
||||
$this->tables[] = 'rec2';
|
||||
|
@ -39,9 +39,29 @@ class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase
|
||||
parent::prepareTables();
|
||||
}
|
||||
|
||||
public function prepareData() { }
|
||||
public function prepareData()
|
||||
{ }
|
||||
|
||||
public function testAssignFieldsToProxies()
|
||||
public function testAssigningAutoincId()
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$this->assertEqual($user->id, null);
|
||||
|
||||
$user->name = 'zYne';
|
||||
|
||||
$user->save();
|
||||
|
||||
$this->assertEqual($user->id, 1);
|
||||
|
||||
$user->id = 2;
|
||||
|
||||
$this->assertEqual($user->id, 2);
|
||||
|
||||
$user->save();
|
||||
}
|
||||
/**
|
||||
public function testAssignFieldsToProxies()
|
||||
{
|
||||
$user = new User();
|
||||
$user->name = 'someuser';
|
||||
@ -166,66 +186,67 @@ class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase
|
||||
$this->assertEqual($user->password, '123');
|
||||
|
||||
$this->assertEqual($count, count($this->dbh));
|
||||
}
|
||||
|
||||
public function testProxyToDirtyToProxy() {
|
||||
|
||||
define('UNAME','someuser') ;
|
||||
define('UPWD1','123') ;
|
||||
define('UPWD2','456') ;
|
||||
define('ULNAME','somelogin') ;
|
||||
|
||||
$user = new User() ;
|
||||
$user->name = UNAME ;
|
||||
$user->password = UPWD1 ;
|
||||
$user->loginname = ULNAME ;
|
||||
$user->save() ;
|
||||
|
||||
$this->assertEqual($user->name,UNAME) ;
|
||||
$this->assertEqual($user->password,UPWD1) ;
|
||||
$this->assertEqual($user->loginname,ULNAME) ;
|
||||
|
||||
// to make sure it is saved correctly
|
||||
$user1 = $this->connection->queryOne("FROM User u WHERE u.name = '" . UNAME . "'");
|
||||
$this->assertEqual($user1->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($user1->name,UNAME) ;
|
||||
$this->assertEqual($user1->password,UPWD1) ;
|
||||
$this->assertEqual($user1->loginname,ULNAME) ;
|
||||
|
||||
$this->connection->clear() ;
|
||||
//$this->clearCache() ;
|
||||
|
||||
// now lets fetch partially the object
|
||||
//$users = Doctrine_Query::create($this->connection)->select('u.name')->from('User u')->where("u.name='someuser'")->execute() ;
|
||||
//$user2 = $users[0] ;
|
||||
$user2 = $this->connection->queryOne("SELECT u.name FROM User u WHERE u.name = '" . UNAME . "'");
|
||||
|
||||
// the object should be in state proxy with only 'name' fetched ...
|
||||
$this->assertEqual($user2->state(), Doctrine_Record::STATE_PROXY);
|
||||
$this->assertEqual($user2->name,UNAME) ;
|
||||
$this->assertEqual($user2->password,null) ;
|
||||
$this->assertEqual($user2->loginname,null) ;
|
||||
|
||||
// lets edit the object
|
||||
$user2->password = UPWD2 ;
|
||||
|
||||
// now it should be dirty (but may be PDIRTY ... ?)
|
||||
$this->assertEqual($user2->state(),Doctrine_Record::STATE_DIRTY) ;
|
||||
$this->assertEqual($user2->name,UNAME) ;
|
||||
$this->assertEqual($user2->password,UPWD2) ;
|
||||
$this->assertEqual($user2->loginname,null) ;
|
||||
|
||||
// lets save
|
||||
$user2->save() ;
|
||||
|
||||
// the logic would suggest the object to go back to PROXY mode (becausse $user2->loginname is null aka not sync with DB)
|
||||
$boolState = ($user2->loginname == null) && ($user2->state() === Doctrine_Record::STATE_PROXY) ;
|
||||
// this one will currently fail
|
||||
$this->assertTrue($boolState) ;
|
||||
// this will also currently fail (becausse it currently goes back to STATE_CLEAN, which shouldnt be the case)
|
||||
//$this->assertEqual($user2->state(), Doctrine_Record::STATE_PROXY);
|
||||
$this->assertEqual($user2->name,UNAME) ;
|
||||
$this->assertEqual($user2->password,UPWD2) ;
|
||||
$this->assertEqual($user2->loginname,null) ;
|
||||
}
|
||||
|
||||
public function testProxyToDirtyToProxy() {
|
||||
|
||||
define('UNAME','someuser') ;
|
||||
define('UPWD1','123') ;
|
||||
define('UPWD2','456') ;
|
||||
define('ULNAME','somelogin') ;
|
||||
|
||||
$user = new User() ;
|
||||
$user->name = UNAME ;
|
||||
$user->password = UPWD1 ;
|
||||
$user->loginname = ULNAME ;
|
||||
$user->save() ;
|
||||
|
||||
$this->assertEqual($user->name,UNAME) ;
|
||||
$this->assertEqual($user->password,UPWD1) ;
|
||||
$this->assertEqual($user->loginname,ULNAME) ;
|
||||
|
||||
// to make sure it is saved correctly
|
||||
$user1 = $this->connection->queryOne("FROM User u WHERE u.name = '" . UNAME . "'");
|
||||
$this->assertEqual($user1->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($user1->name,UNAME) ;
|
||||
$this->assertEqual($user1->password,UPWD1) ;
|
||||
$this->assertEqual($user1->loginname,ULNAME) ;
|
||||
|
||||
$this->connection->clear() ;
|
||||
//$this->clearCache() ;
|
||||
|
||||
// now lets fetch partially the object
|
||||
//$users = Doctrine_Query::create($this->connection)->select('u.name')->from('User u')->where("u.name='someuser'")->execute() ;
|
||||
//$user2 = $users[0] ;
|
||||
$user2 = $this->connection->queryOne("SELECT u.name FROM User u WHERE u.name = '" . UNAME . "'");
|
||||
|
||||
// the object should be in state proxy with only 'name' fetched ...
|
||||
$this->assertEqual($user2->state(), Doctrine_Record::STATE_PROXY);
|
||||
$this->assertEqual($user2->name,UNAME) ;
|
||||
$this->assertEqual($user2->password,null) ;
|
||||
$this->assertEqual($user2->loginname,null) ;
|
||||
|
||||
// lets edit the object
|
||||
$user2->password = UPWD2 ;
|
||||
|
||||
// now it should be dirty (but may be PDIRTY ... ?)
|
||||
$this->assertEqual($user2->state(),Doctrine_Record::STATE_DIRTY) ;
|
||||
$this->assertEqual($user2->name,UNAME) ;
|
||||
$this->assertEqual($user2->password,UPWD2) ;
|
||||
$this->assertEqual($user2->loginname,null) ;
|
||||
|
||||
// lets save
|
||||
$user2->save() ;
|
||||
|
||||
// the logic would suggest the object to go back to PROXY mode (becausse $user2->loginname is null aka not sync with DB)
|
||||
$boolState = ($user2->loginname == null) && ($user2->state() === Doctrine_Record::STATE_PROXY) ;
|
||||
// this one will currently fail
|
||||
$this->assertTrue($boolState) ;
|
||||
// this will also currently fail (becausse it currently goes back to STATE_CLEAN, which shouldnt be the case)
|
||||
//$this->assertEqual($user2->state(), Doctrine_Record::STATE_PROXY);
|
||||
$this->assertEqual($user2->name,UNAME) ;
|
||||
$this->assertEqual($user2->password,UPWD2) ;
|
||||
$this->assertEqual($user2->loginname,null) ;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -42,6 +42,67 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
parent::prepareTables();
|
||||
}
|
||||
|
||||
public function testOne2OneForeign()
|
||||
{
|
||||
$user = new User();
|
||||
$user->name = "Richard Linklater";
|
||||
|
||||
$rel = $user->getTable()->getRelation('Account');
|
||||
|
||||
$this->assertTrue($rel instanceof Doctrine_Relation_ForeignKey);
|
||||
|
||||
$account = $user->Account;
|
||||
$account->amount = 1000;
|
||||
$this->assertTrue($account instanceof Account);
|
||||
$this->assertEqual($account->state(), Doctrine_Record::STATE_TDIRTY);
|
||||
$this->assertEqual($account->entity_id->getOid(), $user->getOid());
|
||||
$this->assertEqual($account->amount, 1000);
|
||||
$this->assertEqual($user->name, "Richard Linklater");
|
||||
|
||||
$user->save();
|
||||
$this->assertEqual($account->entity_id, $user->id);
|
||||
|
||||
$user->refresh();
|
||||
|
||||
$account = $user->Account;
|
||||
$this->assertTrue($account instanceof Account);
|
||||
$this->assertEqual($account->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($account->entity_id, $user->id);
|
||||
$this->assertEqual($account->amount, 1000);
|
||||
$this->assertEqual($user->name, "Richard Linklater");
|
||||
|
||||
|
||||
$user = new User();
|
||||
$user->name = 'John Rambo';
|
||||
$account = $user->Account;
|
||||
$account->amount = 2000;
|
||||
$this->assertEqual($account->getTable()->getColumnNames(), array('id', 'entity_id', 'amount'));
|
||||
|
||||
$this->connection->flush();
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertTrue($account instanceof Account);
|
||||
|
||||
$this->assertEqual($account->getTable()->getColumnNames(), array('id', 'entity_id', 'amount'));
|
||||
$this->assertEqual($account->entity_id, $user->id);
|
||||
$this->assertEqual($account->amount, 2000);
|
||||
|
||||
|
||||
$user = $user->getTable()->find($user->id);
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
|
||||
|
||||
|
||||
$account = $user->Account;
|
||||
$this->assertTrue($account instanceof Account);
|
||||
|
||||
$this->assertEqual($account->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($account->getTable()->getColumnNames(), array('id', 'entity_id', 'amount'));
|
||||
|
||||
$this->assertEqual($account->entity_id, $user->id);
|
||||
$this->assertEqual($account->amount, 2000);
|
||||
$this->assertEqual($user->name, "John Rambo");
|
||||
|
||||
}
|
||||
|
||||
public function testIssetForPrimaryKey()
|
||||
{
|
||||
$this->assertTrue(isset($this->users[0]->id));
|
||||
@ -50,9 +111,9 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
$user = new User();
|
||||
|
||||
$this->assertFalse(isset($user->id));
|
||||
$this->assertFalse(isset($user['id']));
|
||||
$this->assertFalse($user->contains('id'));
|
||||
$this->assertTrue(isset($user->id));
|
||||
$this->assertTrue(isset($user['id']));
|
||||
$this->assertTrue($user->contains('id'));
|
||||
}
|
||||
|
||||
public function testNotNullConstraint()
|
||||
@ -312,60 +373,6 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
|
||||
|
||||
}
|
||||
|
||||
public function testOne2OneForeign()
|
||||
{
|
||||
|
||||
$user = new User();
|
||||
$user->name = "Richard Linklater";
|
||||
$account = $user->Account;
|
||||
$account->amount = 1000;
|
||||
$this->assertTrue($account instanceof Account);
|
||||
$this->assertEqual($account->state(), Doctrine_Record::STATE_TDIRTY);
|
||||
$this->assertEqual($account->entity_id->getOid(), $user->getOid());
|
||||
$this->assertEqual($account->amount, 1000);
|
||||
$this->assertEqual($user->name, "Richard Linklater");
|
||||
|
||||
$user->save();
|
||||
|
||||
$user->refresh();
|
||||
$account = $user->Account;
|
||||
$this->assertTrue($account instanceof Account);
|
||||
$this->assertEqual($account->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($account->entity_id, $user->id);
|
||||
$this->assertEqual($account->amount, 1000);
|
||||
$this->assertEqual($user->name, "Richard Linklater");
|
||||
|
||||
|
||||
$user = new User();
|
||||
$user->name = "John Rambo";
|
||||
$account = $user->Account;
|
||||
$account->amount = 2000;
|
||||
$this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount"));
|
||||
|
||||
$this->connection->flush();
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertTrue($account instanceof Account);
|
||||
|
||||
$this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount"));
|
||||
$this->assertEqual($account->entity_id, $user->id);
|
||||
$this->assertEqual($account->amount, 2000);
|
||||
|
||||
|
||||
$user = $user->getTable()->find($user->id);
|
||||
$this->assertEqual($user->state(), Doctrine_Record::STATE_CLEAN);
|
||||
|
||||
|
||||
$account = $user->Account;
|
||||
$this->assertTrue($account instanceof Account);
|
||||
|
||||
$this->assertEqual($account->state(), Doctrine_Record::STATE_CLEAN);
|
||||
$this->assertEqual($account->getTable()->getColumnNames(), array("id","entity_id","amount"));
|
||||
|
||||
$this->assertEqual($account->entity_id, $user->id);
|
||||
$this->assertEqual($account->amount, 2000);
|
||||
$this->assertEqual($user->name, "John Rambo");
|
||||
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
|
137
tests/Ticket/424BTestCase.php
Normal file
137
tests/Ticket/424BTestCase.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?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_Ticket424B_TestCase
|
||||
*
|
||||
* This test case tests many-many relationship with non-autoincrement primary key
|
||||
*
|
||||
* @package Doctrine
|
||||
* @author Tamcy <7am.online@gmail.com>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_Ticket_424B_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public function prepareData()
|
||||
{ }
|
||||
|
||||
public function prepareTables()
|
||||
{
|
||||
$this->tables = array('mmrUser_B', 'mmrGroup_B', 'mmrGroupUser_B');
|
||||
|
||||
parent::prepareTables();
|
||||
}
|
||||
|
||||
protected function newGroup($code, $name)
|
||||
{
|
||||
$group = new mmrGroup_B();
|
||||
$group->id = $code;
|
||||
$group->name = $name;
|
||||
$group->save();
|
||||
return $group;
|
||||
}
|
||||
|
||||
protected function newUser($code, $name, $groups)
|
||||
{
|
||||
$u = new mmrUser_B();
|
||||
$u->id = $code;
|
||||
$u->name = $name;
|
||||
|
||||
foreach ($groups as $idx=>$group) {
|
||||
$u->Group[$idx] = $group;
|
||||
}
|
||||
|
||||
$u->save();
|
||||
return $u;
|
||||
}
|
||||
|
||||
public function testManyManyRelationWithAliasColumns()
|
||||
{
|
||||
$groupA = $this->newGroup(1, 'Group A');
|
||||
$groupB = $this->newGroup(2, 'Group B');
|
||||
$groupC = $this->newGroup(3, 'Group C');
|
||||
|
||||
$john = $this->newUser(1, 'John', array($groupA, $groupB));
|
||||
$peter = $this->newUser(2, 'Peter', array($groupA, $groupC));
|
||||
$alan = $this->newUser(3, 'Alan', array($groupB, $groupC));
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$gu = $q->from('mmrGroupUser_B')->execute();
|
||||
$this->assertEqual(count($gu), 6);
|
||||
|
||||
// Direct query
|
||||
$q = new Doctrine_Query();
|
||||
$gu = $q->from('mmrGroupUser_B')->where('group_id = ?', $groupA->id)->execute();
|
||||
$this->assertEqual(count($gu), 2);
|
||||
|
||||
// Query by join
|
||||
$q = new Doctrine_Query();
|
||||
$userOfGroupAByName = $q->from('mmrUser_B u, u.Group g')
|
||||
->where('g.name = ?', array($groupA->name));
|
||||
$q->execute();
|
||||
$this->assertEqual(count($userOfGroupAByName), 2);
|
||||
|
||||
}
|
||||
}
|
||||
class mmrUser_B extends Doctrine_Record
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->hasMany('mmrGroup_B as Group', array('local' => 'user_id',
|
||||
'foreign' => 'group_id',
|
||||
'refClass' => 'mmrGroupUser_B'));
|
||||
|
||||
}
|
||||
|
||||
public function setTableDefinition()
|
||||
{
|
||||
// Works when
|
||||
$this->hasColumn('id', 'string', 30, array ( 'primary' => true));
|
||||
$this->hasColumn('name', 'string', 30);
|
||||
}
|
||||
}
|
||||
|
||||
class mmrGroup_B extends Doctrine_Record
|
||||
{
|
||||
public function setUp() {
|
||||
$this->hasMany('mmrUser_B', array('local' => 'group_id',
|
||||
'foreign' => 'user_id',
|
||||
'refClass' => 'mmrGroupUser_B'));
|
||||
}
|
||||
public function setTableDefinition() {
|
||||
// Works when
|
||||
$this->hasColumn('id', 'string', 30, array ( 'primary' => true));
|
||||
$this->hasColumn('name', 'string', 30);
|
||||
}
|
||||
}
|
||||
|
||||
class mmrGroupUser_B extends Doctrine_Record
|
||||
{
|
||||
public function setTableDefinition()
|
||||
{
|
||||
$this->hasColumn('user_id', 'string', 30, array('primary' => true));
|
||||
$this->hasColumn('group_id', 'string', 30, array('primary' => true));
|
||||
}
|
||||
}
|
137
tests/Ticket/424CTestCase.php
Normal file
137
tests/Ticket/424CTestCase.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?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_Ticket424B_TestCase
|
||||
*
|
||||
* This test case tests many-many relationship with non-autoincrement, alias primary key
|
||||
*
|
||||
* @package Doctrine
|
||||
* @author Tamcy <7am.online@gmail.com>
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
class Doctrine_Ticket_424C_TestCase extends Doctrine_UnitTestCase
|
||||
{
|
||||
public function prepareData()
|
||||
{ }
|
||||
|
||||
public function prepareTables()
|
||||
{
|
||||
$this->tables = array('mmrUser_C', 'mmrGroup_C', 'mmrGroupUser_C');
|
||||
parent::prepareTables();
|
||||
}
|
||||
|
||||
protected function newGroup($code, $name)
|
||||
{
|
||||
$group = new mmrGroup_C();
|
||||
$group->id = $code;
|
||||
$group->name = $name;
|
||||
$group->save();
|
||||
return $group;
|
||||
}
|
||||
|
||||
protected function newUser($code, $name, $groups)
|
||||
{
|
||||
$u = new mmrUser_C();
|
||||
$u->id = $code;
|
||||
$u->name = $name;
|
||||
foreach ($groups as $idx=>$group) {
|
||||
$u->Group[$idx] = $group;
|
||||
}
|
||||
$u->save();
|
||||
return $u;
|
||||
}
|
||||
|
||||
public function testManyManyRelationWithAliasColumns()
|
||||
{
|
||||
$groupA = $this->newGroup(1, 'Group A');
|
||||
$groupB = $this->newGroup(2, 'Group B');
|
||||
$groupC = $this->newGroup(3, 'Group C');
|
||||
|
||||
$john = $this->newUser(1, 'John', array($groupA, $groupB));
|
||||
$peter = $this->newUser(2, 'Peter', array($groupA, $groupC));
|
||||
$alan = $this->newUser(3, 'Alan', array($groupB, $groupC));
|
||||
|
||||
$q = new Doctrine_Query();
|
||||
$gu = $q->from('mmrGroupUser_C')->execute();
|
||||
$this->assertEqual(count($gu), 6);
|
||||
|
||||
// Direct query
|
||||
$q = new Doctrine_Query();
|
||||
$gu = $q->from('mmrGroupUser_C')->where('group_id = ?', $groupA->id)->execute();
|
||||
$this->assertEqual(count($gu), 2);
|
||||
|
||||
// Query by join
|
||||
$q = new Doctrine_Query();
|
||||
$userOfGroupAByName = $q->from('mmrUser_C u, u.Group g')
|
||||
->where('g.name = ?', array($groupA->name));
|
||||
|
||||
$q->execute();
|
||||
|
||||
$this->assertEqual(count($userOfGroupAByName), 2);
|
||||
}
|
||||
}
|
||||
class mmrUser_C extends Doctrine_Record
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->hasMany('mmrGroup_C as Group', array('local' => 'user_id',
|
||||
'foreign' => 'group_id',
|
||||
'refClass' => 'mmrGroupUser_C'));
|
||||
|
||||
}
|
||||
|
||||
public function setTableDefinition()
|
||||
{
|
||||
// Works when
|
||||
$this->hasColumn('g_id as id', 'string', 30, array ( 'primary' => true));
|
||||
$this->hasColumn('name', 'string', 30);
|
||||
}
|
||||
}
|
||||
|
||||
class mmrGroup_C extends Doctrine_Record
|
||||
{
|
||||
public function setUp() {
|
||||
$this->hasMany('mmrUser_C', array('local' => 'group_id',
|
||||
'foreign' => 'user_id',
|
||||
'refClass' => 'mmrGroupUser_C'));
|
||||
}
|
||||
public function setTableDefinition() {
|
||||
// Works when
|
||||
$this->hasColumn('u_id as id', 'string', 30, array ( 'primary' => true));
|
||||
$this->hasColumn('name', 'string', 30);
|
||||
}
|
||||
}
|
||||
|
||||
class mmrGroupUser_C extends Doctrine_Record
|
||||
{
|
||||
public function setTableDefinition()
|
||||
{
|
||||
$this->hasColumn('user_id', 'string', 30, array('primary' => true));
|
||||
$this->hasColumn('group_id', 'string', 30, array('primary' => true));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user