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

Assign unique key to each rule in generated model #208

Open
mohdqasim98 opened this issue Jul 14, 2017 · 4 comments
Open

Assign unique key to each rule in generated model #208

mohdqasim98 opened this issue Jul 14, 2017 · 4 comments

Comments

@mohdqasim98
Copy link

The rules generated in the model should be such that each rule must have its a unique string key,
so that it can be easily overridden in the child model.
Example :

public function rules()
{
    return [
        'bioString'            => ['bio', 'string'],
        'timeZoneValidation'   => ['timezone', 'validateTimeZone'],
        'publicEmailPattern'   => ['public_email', 'email'],
        'gravatarEmailPattern' => ['gravatar_email', 'email'],
    ];
}

So that in the child class , it can be easily overridden like:

public function rules()
{
	$rules = parent::rules();
	$rules['bioString'] = ['bio', 'required'];
}
@keshavchauha
Copy link

some time i also facing problem when override the child model rules so please define unique string key creating model,

@schmunk42
Copy link
Owner

How would we handle combined properties like required?

@uldisn
Copy link
Contributor

uldisn commented Aug 30, 2018

Real rules:

            [['regcode', 'name'], 'required'],
            [['type_id', 'reg_partnet_company_id'], 'integer'],
            [['office_address', 'status'], 'string'],
            [['regcode'], 'string', 'max' => 11],
            [['sepa'], 'string', 'max' => 20],
            [['name', 'address'], 'string', 'max' => 255],
            [['reg_partnet_company_id'], 'exist', 'skipOnError' => true, 'targetClass' => D3cCompany::className(), 'targetAttribute' => ['reg_partnet_company_id' => 'id']],
            [['country_id', 'comunication_language_id'], 'string', 'max' => 3],
            [['country_id'], 'exist', 'skipOnError' => true, 'targetClass' => \yii2d3\d3persons\models\ClCountries::className(), 'targetAttribute' => ['country_id' => 'id']],
            [['comunication_language_id'], 'exist', 'skipOnError' => true, 'targetClass' => \yii2d3\d3persons\models\ClLanguage::className(), 'targetAttribute' => ['comunication_language_id' => 'id']],
            [['type_id'], 'exist', 'skipOnError' => true, 'targetClass' => \yii2d3\d3persons\models\D3cType::className(), 'targetAttribute' => ['type_id' => 'id']],
            ['status', 'in', 'range' => [
                    self::STATUS_PARTNER,
                    self::STATUS_AUTH,
                    self::STATUS_CLOSED
                ]
            ]

with id:

            'required' => [['regcode', 'name'], 'required'],
            'integer' => [['type_id', 'reg_partnet_company_id'], 'integer'],
            'string' => [['office_address', 'status'], 'string'],
            'stringMax11' => [['regcode'], 'string', 'max' => 11],
            'stringMax20' => [['sepa'], 'string', 'max' => 20],
            'stringMax255' => [['name', 'address'], 'string', 'max' => 255],
            'regParnerCompanyIdExist' => [['reg_partnet_company_id'], 'exist', 'skipOnError' => true, 'targetClass' => D3cCompany::className(), 'targetAttribute' => ['reg_partnet_company_id' => 'id']],
            'stringMax2' => [['country_id', 'comunication_language_id'], 'string', 'max' => 3],
            'countryIdExist' => [['country_id'], 'exist', 'skipOnError' => true, 'targetClass' => \yii2d3\d3persons\models\ClCountries::className(), 'targetAttribute' => ['country_id' => 'id']],
            'statusRange' => ['status', 'in', 'range' => [
                    self::STATUS_PARTNER,
                    self::STATUS_AUTH,
                    self::STATUS_CLOSED
                ]
            ]

@schmunk42
Copy link
Owner

This looks tricky, but - as always - PRs welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants