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

Default value for initialization #8

Open
Horat1us opened this issue Dec 12, 2017 · 2 comments
Open

Default value for initialization #8

Horat1us opened this issue Dec 12, 2017 · 2 comments

Comments

@Horat1us
Copy link

Shouldn't it be property to define default value for JsonField?
For example

<?php
class Model extends ActiveRecord {
    public function behaviors() {
        return ['json' => [
            'class' => JsonBehavior::class,
            'attributes' => 'settings',
            'default' => ['key' => 'value],
        ];
    }
}

I need it because I may use settings before validation, so I cant use default validator and need to create own behavior that do initialization.
If you want I can create PR.

@paulzi
Copy link
Owner

paulzi commented Mar 21, 2018

Why do not you use the value when initializing?

class Model extends ActiveRecord {
    public function behaviors() {
        return ['json' => [
            'class' => JsonBehavior::class,
            'attributes' => 'settings',
        ];
    }
    
    public function init()
    {
        $this->settings = new JsonField(['key' => 'value']);
    }
}

@Horat1us
Copy link
Author

Default in configuration is more friendly. Anyway, after 2.0.14 yii release I do not use this library because of built in json support

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

No branches or pull requests

2 participants