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
Fixes #2726: ActiveRecord now fills default values on creating new instance of the model if defaults are available from DB schema #2815
Conversation
…stance of the model if defaults are available from DB schema
This is not correct because it may overwrite the values that are set via constructor. I suggest we introduce a method |
Two more issues:
|
Are we actually setting any values via constructor? |
The framework doesn't, but it's totally valid to do |
In a rest API it will get real values from data source, not default ones. |
Not the case with this PR. Imagine I want to return a user list with only In summary, setting default values is only useful when inserting new records. And even in this case, some users may not like prefilling with default values. |
Makes sense. Changed it to be separate method so the syntax is: $model = new MyModel();
$model->loadDefaultValues()->save(); |
Looks good to me now. Potential future enhancement is to allow loading default values for specific attributes. Probably not needed for now. |
Fixes #2726: ActiveRecord now fills default values on creating new instance of the model if defaults are available from DB schema
If this is run by a function then say I was to do as @qiangxue says with: |
You can't. Use individual assignments after calling |
Pros of this approach: