Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #12766 #12767

Merged
merged 1 commit into from
Apr 4, 2017
Merged
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
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();
}
}