Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Model Validation Generator: add names to the validation rules to allow easier extending #17

Closed
cebe opened this issue Aug 5, 2020 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@cebe
Copy link
Owner

cebe commented Aug 5, 2020

In rules() the array should have (ideally consistent) keys to allow removing or overwriting validation rules in the extending model.

@cebe cebe added the enhancement New feature or request label Aug 5, 2020
@cebe cebe added this to the 2.0 milestone Aug 5, 2020
@Insolita
Copy link
Collaborator

Insolita commented Aug 10, 2020

Have you any ideas about key name generation?

trim, safe and required rules are common for all and can be named by validator... and other with keys 'attribute_validator' ?

public function rules()
    {
        return [
           'trim' => [['message', 'created_at'], 'trim'],
           'required'=> [['post_id', 'message', 'created_at'], 'required'],
           'post_id_integer'=> [['post_id'], 'integer'],
           'post_id_exist' => [['post_id'], 'exist', 'targetRelation' => 'Post'],
            'user_id_integer' => [['user_id'], 'integer'],
            'user_id_exist' => [['user_id'], 'exist', 'targetRelation' => 'User'],
            'message_string' => [['message'], 'string'],
            'created_at_datetime' =>[['created_at'], 'datetime'],
        ];
    }

@Insolita
Copy link
Collaborator

perhaps also we may add into the template for extending model

public function rules()
{
       $rules = parent::rules();
       return $rules;
}

@cebe cebe closed this as completed Aug 16, 2020
cebe pushed a commit that referenced this issue Mar 7, 2023
…ion-rules-and-faker-and-more-if-any

Resolve - Consider x-db-type in validation rules and faker and more if any
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants