Skip to content

Commit

Permalink
Model validation now correctly adds code to message
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurigag committed Mar 3, 2017
1 parent bbc5cff commit 25a504e
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 213 deletions.
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [3.1.0](https://github.com/phalcon/cphalcon/releases/tag/v3.1.0) (2016-XX-XX)
# [3.1.0](https://github.com/phalcon/cphalcon/releases/tag/v3.1.0) (2017-XX-XX)
- Added `Phalcon\Validation\Validator\Callback`, `Phalcon\Validation::getData`
- Added the ability to truncate database tables
- Added `Phalcon\Mvc\Model\Binder`, class used for binding models to parameters in dispatcher, micro, added `Phalcon\Dispatcher::getBoundModels` and `Phalcon\Mvc\Micro::getBoundModels` to getting bound models, added `Phalcon\Mvc\Micro\Collection\LazyLoader::callMethod`
Expand All @@ -8,9 +8,22 @@
- Added the ability to specify what empty means in the 'allowEmpty' option of the validators. Now it accepts as well an array specifying what's empty, for example ['', false]
- Added the ability to use `Phalcon\Validation` with `Phalcon\Mvc\Collection`, deprecated `Phalcon\Mvc\Collection::validationHasFailed`
- Fixes internal cache saving in `Phalcon\Mvc\Model\Binder` when no cache backend is used
- Added the ability to get original values from `Phalcon\Mvc\Model\Binder`, added `Phalcon\Mvc\Micro::getModelBinder`, `Phalcon\Dispatcher::getModelBinder`
- Added `prepend` parameter to `Phalcon\Loader::register` to specify autoloader's loading order to top most
- Fixed `Phalcon\Session\Bag::remove` to initialize the bag before removing a value [#12647](https://github.com/phalcon/cphalcon/pull/12647)
- Fixed `Phalcon\Mvc\Model::getChangedFields` to correct detect changes from NULL to Zero [#12628](https://github.com/phalcon/cphalcon/issues/12628)
- Fixed `Phalcon\Mvc\Model::validate` to correctly set code message [#12645](https://github.com/phalcon/cphalcon/issues/12645)

# [3.0.4](https://github.com/phalcon/cphalcon/releases/tag/v3.0.4) (XXXX-XX-XX)
# [3.0.4](https://github.com/phalcon/cphalcon/releases/tag/v3.0.4) (2017-02-20)
- Fixed Isnull check is not correct when the model field defaults to an empty string. [#12507](https://github.com/phalcon/cphalcon/issues/12507)
- Fixed `Phalcon\Forms\Element::label` to accept 0 as label instead of validating it as empty. [#12148](https://github.com/phalcon/cphalcon/issues/12148)
- Fixed `Phalcon\Crypt::getAvailableCiphers`, `Phalcon\Crypt::decrypt`, `Phalcon\Crypt::encrypt` by getting missed aliases for ciphers [#12539](https://github.com/phalcon/cphalcon/pull/12539)
- Fixed `Phalcon\Mvc\Model` by adding missed `use` statement for `ResultsetInterface` [#12574](https://github.com/phalcon/cphalcon/pull/12574)
- Fixed adding role after setting default action [#12573](https://github.com/phalcon/cphalcon/issues/12573)
- Fixed except option in `Phalcon\Validation\Validator\Uniquenss` to allow using except fields other than unique fields
- Cleaned `Phalcon\Translate\Adapter\Gettext::query` and removed ability to pass custom domain [#12598](https://github.com/phalcon/cphalcon/issues/12598), [#12606](https://github.com/phalcon/cphalcon/pull/12606)
- Fixed `Phalcon\Validation\Message\Group::offsetUnset` to correct unsetting a message by index [#12455](https://github.com/phalcon/cphalcon/issues/12455)
- Fix using `Phalcon\Acl\Role` and `Phalcon\Acl\Resource` as parameters for `Phalcon\Acl\Adapter\Memory::isAllowed`

# [3.0.3](https://github.com/phalcon/cphalcon/releases/tag/v3.0.3) (2016-12-24)
- Fixed implementation of Iterator interface in a `Phalcon\Forms\Form` that could cause a run-time warning
Expand Down
3 changes: 2 additions & 1 deletion phalcon/mvc/model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,8 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface
new Message(
message->getMessage(),
message->getField(),
message->getType()
message->getType(),
message->getCode()
)
);
}
Expand Down
60 changes: 60 additions & 0 deletions tests/_data/models/Validation/Robots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Phalcon\Test\Models\Validation;

use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Resultset\Simple;
use Phalcon\Test\Models\RobotsParts;
use Phalcon\Validation;
use Phalcon\Validation\Validator\PresenceOf;

/**
* \Phalcon\Test\Models\Validation\Robots
*
* @method static int countByType(string $type)
* @method static Simple findByType(string $type)
* @method static Robots findFirstById(string | int $id)
*
* @copyright 2011-2017 Phalcon Team
* @link https://phalconphp.com
* @author Andres Gutierrez <[email protected]>
* @author Nikolaos Dimopoulos <[email protected]>
* @package Phalcon\Test\Models\Validation
*
* 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 function initialize()
{
$this->hasMany(
'id',
RobotsParts::class,
'robots_id',
[
'foreignKey' => true,
'reusable' => false,
'alias' => 'parts',
]
);
}

public function validation()
{
$validation = new Validation();
$validation->add(
'name',
new PresenceOf(
[
'message' => 'Name is required',
'code' => 20,
]
)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Phalcon\Test\Models;
namespace Phalcon\Test\Models\Validation;

use Phalcon\Mvc\Model;
use Phalcon\Validation;
Expand All @@ -14,7 +14,7 @@
use Phalcon\Validation\Validator\StringLength;

/**
* \Phalcon\Test\Models\Subscriptores
* \Phalcon\Test\Models\Validation\Subscriptores
*
* @property int id
* @property string email
Expand All @@ -25,7 +25,7 @@
* @link http://www.phalconphp.com
* @author Andres Gutierrez <[email protected]>
* @author Serghei Iakovlev <[email protected]>
* @package Phalcon\Test\Models
* @package Phalcon\Test\Models\Validation
*
* The contents of this file are subject to the New BSD License that is
* bundled with this package in the file docs/LICENSE.txt
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Mvc/Model/Helpers/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use UnitTester;
use Phalcon\Db\RawValue;
use Phalcon\Mvc\Model\Message;
use Phalcon\Test\Models\Subscriptores;
use Phalcon\Test\Models\Validation\Subscriptores;

class Validation
{
Expand Down
Loading

0 comments on commit 25a504e

Please sign in to comment.