Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurigag committed Apr 4, 2017
1 parent 3622bc1 commit 7e444d0
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# [3.1.2](https://github.com/phalcon/cphalcon/releases/tag/v3.1.2) (2017-XX-XX)
- Fixed PHP 7.1 issues [#12055](https://github.com/phalcon/cphalcon/issues/12055)
- Fixed `Imagick::getVersion()` error in some system [#12729](https://github.com/phalcon/cphalcon/pull/12729)
- Fixed `Phalcon\Mvc\Model::_doLowInsert` to properly set snapshot when having default values and public properties [#12766](https://github.com/phalcon/cphalcon/issues/12766)

# [3.1.1](https://github.com/phalcon/cphalcon/releases/tag/v3.1.1) (2017-03-25)
- Fixed undefined index warning on existing cached resultsets
Expand Down
4 changes: 3 additions & 1 deletion phalcon/mvc/model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,10 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
if fetch value, this->{attributeField} {

if value === null && isset defaultValues[field] {
let snapshot[attributeField] = null;
let value = connection->getDefaultValue();
} else {
let snapshot[attributeField] = value;
}

/**
Expand All @@ -2301,7 +2304,6 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
}

let fields[] = field, values[] = value, bindTypes[] = bindType;
let snapshot[attributeField] = value;
} else {

if isset defaultValues[field] {
Expand Down
45 changes: 45 additions & 0 deletions tests/_data/models/DynamicUpdate/Robots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Phalcon\Test\Models\DynamicUpdate;

use Phalcon\Mvc\Model;
use Phalcon\Test\Models\RobotsParts;

/**
* \Phalcon\Test\Models\DynamicUpdate\Robots
*
* @copyright 2011-2017 Phalcon Team
* @link https://phalconphp.com
* @author Andres Gutierrez <[email protected]>
* @author Serghei Iakovlev <[email protected]>
* @package Phalcon\Test\Models\DynamicUpdate
*
* @property int $id
* @property string $name
* @property string $type
* @property int $year
* @property string $datetime
* @property string $deleted
* @property string $text
*
* @method static Robots findFirst($parameters = null)
* @method static Robots[] find($parameters = null)
*
* The contents of this file are subject to the New BSD License that is
* bundled with this package in the file docs/LICENSE.txt
*
* If you did not receive a copy of the license and are unable to obtain it
* through the world-wide-web, please send an email to [email protected]
* so that we can send you a copy immediately.
*/
class Robots extends Model
{
public $year;

public function initialize()
{
$this->hasMany('id', RobotsParts::class, 'robots_id');

$this->useDynamicUpdate(true);
}
}
48 changes: 48 additions & 0 deletions tests/unit/Mvc/Model/DynamicUpdateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Phalcon\Test\Unit\Mvc\Model;

use Phalcon\Test\Models\DynamicUpdate\Robots;
use Phalcon\Test\Module\UnitTest;

/**
* \Phalcon\Test\Unit\Mvc\Model\DynamicUpdateTest
* Tests the Phalcon\Mvc\Model component
*
* @copyright (c) 2011-2017 Phalcon Team
* @link https://phalconphp.com
* @author Andres Gutierrez <[email protected]>
* @author Serghei Iakovlev <[email protected]>
* @author Wojciech Ślawski <[email protected]>
* @package Phalcon\Test\Unit\Mvc\Model
*
* The contents of this file are subject to the New BSD License that is
* bundled with this package in the file docs/LICENSE.txt
*
* If you did not receive a copy of the license and are unable to obtain it
* through the world-wide-web, please send an email to [email protected]
* so that we can send you a copy immediately.
*/
class DynamicUpdateTest extends UnitTest
{
/**
* Tests dynamic update create then update
*
* @author Wojciech Ślawski <[email protected]>
* @issue 12766
* @since 2017-04-04
*/
public function testIssue12766()
{
$robots = new Robots();
$robots->name = 'Test';
$robots->type = 'mechanical';
$robots->datetime = (new \DateTime())->format('Y-m-d');
$robots->text = 'text';

$robots->create();

$robots->year = 2017;
$robots->update();
}
}

0 comments on commit 7e444d0

Please sign in to comment.