1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Ticket 330 closed.

This commit is contained in:
zYne 2007-06-13 20:59:05 +00:00
parent e1fb5e5345
commit a28c399c1c

View File

@ -15,41 +15,41 @@
class stNode extends Doctrine_Record class stNode extends Doctrine_Record
{ {
public function setTableDefinition() public function setTableDefinition()
{ {
$this->setTableName('node_node'); $this->setTableName('node_node');
$this->hasColumn('title', 'string', 255, array ()); $this->hasColumn('title', 'string', 255, array ());
} }
public function setUp() public function setUp()
{ {
$this->hasOne('stNodeDetail as detail', 'stNodeDetail.node_id' , array( 'onDelete'=>'cascade')); $this->hasOne('stNodeDetail as detail', 'stNodeDetail.node_id' , array( 'onDelete'=>'cascade'));
} }
} }
class stNodeDetail extends Doctrine_Record class stNodeDetail extends Doctrine_Record
{ {
public function setTableDefinition() public function setTableDefinition()
{ {
$this->setTableName('node_detail'); $this->setTableName('node_detail');
$this->hasColumn('node_id', 'integer', 10, array ( 'unique' => true,)); $this->hasColumn('node_id', 'integer', 10, array ( 'unique' => true,));
$this->hasColumn('null_column', 'string', 255, array ('default'=>null)); $this->hasColumn('null_column', 'string', 255, array ('default'=>null));
$this->hasColumn('is_bool', 'boolean', null, array ('default' => 0,)); $this->hasColumn('is_bool', 'boolean', null, array ('default' => 0,));
$this->option('type', 'MyISAM'); $this->option('type', 'MyISAM');
} }
public function setUp() public function setUp()
{ {
$this->hasOne('stNode as node', 'stNodeDetail.article_id', array('foreign' => 'id' , 'onDelete'=>'cascade')); $this->hasOne('stNode as node', 'stNodeDetail.article_id', array('foreign' => 'id' , 'onDelete'=>'cascade'));
} }
} }
class Doctrine_Ticket330_TestCase extends Doctrine_UnitTestCase class Doctrine_Ticket330_TestCase extends Doctrine_UnitTestCase
{ {
public function prepareData() public function prepareData()
{ } { }
public function prepareTables() public function prepareTables()
@ -58,46 +58,38 @@ class Doctrine_Ticket330_TestCase extends Doctrine_UnitTestCase
public function testUnnecessaryQueries() public function testUnnecessaryQueries()
{ {
$node1 = new stNode(); $node1 = new stNode();
$node1->set('title', 'first node'); $node1->set('title', 'first node');
$node1->detail->set('is_bool', true); $node1->detail->set('is_bool', true);
$node1->save(); $node1->save();
$node2 = new stNode(); $node2 = new stNode();
$node2->set('title', 'second node'); $node2->set('title', 'second node');
$node2->detail->set('null_column', 'value'); $node2->detail->set('null_column', 'value');
$node2->detail->set('is_bool', false); $node2->detail->set('is_bool', false);
$node2->save(); $node2->save();
$nodes = Doctrine_Query::create() $nodes = Doctrine_Query::create()
->select('n.title, d.null_column, d.is_bool') ->select('n.title, d.*')
->from('stNode n, n.detail d') ->from('stNode n, n.detail d')
->execute(); ->orderby('n.id')
->execute();
$prevCount = $this->dbh->count(); $prevCount = $this->dbh->count();
foreach ( $nodes as $node ) $this->assertEqual($nodes[0]->detail->get('is_bool'), true);
{ $this->assertEqual($nodes[0]->detail->get('null_column'), null);
if ( $node->get('title') == 'first node')
{
$this->assertEqual($node->detail->get('is_bool'), true);
$this->assertEqual($node->detail->get('null_column'), null);
// Unnecessary query is triggered on line before due to null value column.
$this->assertEqual($this->dbh->count(), $prevCount);
$prevCount = $this->dbh->count(); // Unnecessary query is triggered on line before due to null value column.
} $this->assertEqual($this->dbh->count(), $prevCount);
else
{
$this->assertEqual($node->detail->get('null_column'), 'value');
$this->assertEqual($node->detail->get('is_bool'), false);
// Unecessary query is triggered on line before due to false value column
$this->assertEqual($this->dbh->count(), $prevCount);
}
}
$this->assertEqual($this->dbh->count(), $prevCount); $prevCount = $this->dbh->count();
$this->assertEqual($nodes[1]->detail->get('null_column'), 'value');
$this->assertEqual($nodes[1]->detail->get('is_bool'), false);
// Unecessary query is triggered on line before due to false value column
$this->assertEqual($this->dbh->count(), $prevCount);
} }
} }