We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Как сделать валидацию составного ключа?

Всем привет.

У меня в таблице имеется уникальный составной ключ, состоящий из полей ('position', 'controller', 'action')

В модели я прописал:

public function validation() {
     $validator = new Phalcon\Validation();
     $validator->add(
         [
             "position",
             "controller",
             "action",
         ],
         new Phalcon\Validation\Validator\Uniqueness()
     );
     return $this->validate($validator);
}

Валидация по составному ключу не работает. Выдает:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-admin_access-' for key 'position_controller_action'

Судя по всему по каждому полю отдельно проверяет а не по всем вместе. Как сделать валидацию по составному ключу в модели?

Решение из этой темы НЕ ПОДХОДИТ: https://forum.phalcon.io/discussion/4205/phalcon-model-validate-uniqueness-by-two-fields

public function validation()
{
    $this->validate(new Uniqueness(array(
        'field' => array('email', 'name')
    )));
}

Не подходит, так как метод Validate должен принимать \Phalcon\ValidationInterface который в свою очередь принимает правила валидации через метод:

public function add($field, \Phalcon\Validation\ValidatorInterface $validator) {}

Как сделать валидацию по составному ключу в модели?

edited May '17

Как сделать валидацию по составному ключу в модели?

Just write your own validation class which implement \Phalcon\Validation\ValidatorInterface.

P.S. Use english, in this forum you must.

edited May '17

Как сделать валидацию по составному ключу в модели?

Just write your own validation class which implement \Phalcon\Validation\ValidatorInterface.

Hi, Kostya. Can you write some examples for that implement, which provide composite key validation?

P.S. Use english, in this forum you must.

I did not found any rules on this forum that would say that I should write in English. Is this your personal wish or the official position of this forum? If official, please send me the policy where it says that. Tnx

I could answer you in hungarian, but that wouldn't be very helpful to you (or the other hundreds of viewers), would it? :P

The aim of these forums are to provide a central hub for Q&A about Phalcon. If we were to use our national languages, the usefulness of this site would be practically non-existent. This rule is not mentioned anywhere on the forums, because it should be self-evident...

When you post a question, you're not only helping yourself, but also other people who take the effort to search about their issues before posting it :P

edited May '17

[OFFTOP]

I could answer you in hungarian, but that wouldn't be very helpful to you (or the other hundreds of viewers), would it? :P

The aim of these forums are to provide a central hub for Q&A about Phalcon. If we were to use our national languages, the usefulness of this site would be practically non-existent. This rule is not mentioned anywhere on the forums, because it should be self-evident...

When you post a question, you're not only helping yourself, but also other people who take the effort to search about their issues before posting it :P

I think that ~320million users of the Russian-speaking segment of the Internet somewhat incorrectly deal with the number of users in Hungarian, comparable to the population of Kiev or St. Petersburg :D

Documentation of Phalcon is also provided in Russian, which indicates a large Russian-speaking community, comparable to the English-speaking community.

Http://docs.phalconphp.ru/en/latest/

Http://docs.phalconphp.ru

Accordingly, I believe that there is also a Russian-speaking audience on the forum.

In the end, for those who do not know Russian, there is also a Google translator)

[/OFFTOP]

Yes, hungarian speakers number around 30mil in the world, but that's not the point. The docs are also provided in hungarian, but that does not mean the forums should be flooded with national discussions. It's not designed for that.

English is the de-facto language for science and computer engineering, for no other than historical reasons. If you don't see rationale in that and in my previous post, i'm afraid your motivation is more of a political kind.

I hope you also realize that google translate makes a shitshow out of text like technical discussions.

If you want russian speaking forums, deploy https://github.com/phalcon/forum on your favourite server and have fun there ;]



203

请使用英语。Please use English, or we can't read it