Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

DC-797 - Record hydrated as dirty if optional relation is empty #8

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Doctrine/Null.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @version $Revision: 7490 $
* @author Konsta Vesterinen <[email protected]>
*/
final class Doctrine_Null
final class Doctrine_Null implements Countable
{
public function exists()
{
Expand All @@ -44,4 +44,9 @@ public function __toString()
{
return '';
}

public function count()
{
return 0;
}
}
4 changes: 4 additions & 0 deletions lib/Doctrine/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,10 @@ protected function _isValueModified($type, $old, $new)
return true;
}

if (($old === null || $old instanceof Doctrine_Null) && ($new === null || $new instanceof Doctrine_Null)) {
return false;
}

if ($type == 'boolean' && (is_bool($old) || is_numeric($old)) && (is_bool($new) || is_numeric($new)) && $old == $new) {
return false;
} else if (in_array($type, array('decimal', 'float')) && is_numeric($old) && is_numeric($new)) {
Expand Down
1 change: 1 addition & 0 deletions tests/Ticket/AyoubTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function testTest()
$sura->Translation['transliteration']->name = $name;
$sura->Ticket_Ayoub_Place->Translation['transliteration']->name = $placeName;
$sura->Ticket_Ayoub_Place->state('TDIRTY');
$sura->state('TDIRTY');
$sura->save();
$reopened = Doctrine_Core::getTable('Ticket_Ayoub_Sura')->findOneById($sura->id);
$this->assertEqual($name, $reopened->Translation['transliteration']->name);
Expand Down
110 changes: 110 additions & 0 deletions tests/Ticket/DC797TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?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.doctrine-project.org>.
*/

/**
* Doctrine_Ticket_DC797_TestCase
*
* Tests hydration of (optional) 1-to-1 relations, specifically whether they
* are hydrated in a clean state
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.doctrine-project.org
* @since 1.0
* @version $Revision$
*/
class Doctrine_Ticket_DC797_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{
$foo = new DC797_Foo();
$foo->save();
}

public function prepareTables()
{
$this->tables = array('DC797_Foo', 'DC797_Bar');
parent::prepareTables();
}

public function testOneToOneHydrationDoesNotMarkResultModified()
{
$collection = Doctrine_Query::create()->from('DC797_Foo f')->leftJoin('f.DC797_Bar b')->execute();

$this->assertEqual($collection->isModified(), false);
$this->assertEqual($collection[0]->isModified(), false);
}
}

class DC797_Foo extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'primary' => true,
'autoincrement' => true,
'unsigned' => true,
'length' => 4,
));
$this->hasColumn('bar_id', 'integer', 4, array(
'type' => 'integer',
'notnull' => false,
'unsigned' => true,
'length' => 4,
));
}

public function setUp()
{
parent::setUp();

$this->hasOne('DC797_Bar', array(
'local' => 'bar_id',
'foreign' => 'id'
));
}
}

class DC797_Bar extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'primary' => true,
'autoincrement' => true,
'unsigned' => true,
'length' => 4,
));
}

public function setUp()
{
parent::setUp();

$this->hasOne('DC797_Foo', array(
'local' => 'id',
'foreign' => 'bar_id'
));
}
}