active-record icon indicating copy to clipboard operation
active-record copied to clipboard

BaseActiveRecordTrait allow attribute setter

Open anovsiradj opened this issue 1 year ago • 2 comments

Q A
Is bugfix? ✔️
New feature?
Breaks BC? ✔️❌ (maybe)
Fixed issues comma-separated list of tickets # fixed by the PR, if any

attribute setter not working, when canSetProperty('passwordRepeat') said true but, when i do $model->passwordRepeat =$post['password_repeat'] it is throwing Setting unknown property: app\models\User::passwordRepeat.

the code was using the same technique as Yii2 https://github.com/yiisoft/yii2/blob/97ca1f2b18a301d2e932f8eb4b07410d96a17edb/framework/base/Component.php#L178

anovsiradj avatar Mar 30 '24 06:03 anovsiradj

PR Summary

  • Enhancing the Setter Method in BaseActiveRecordTrait The modification ensures that a certain method, designed to assign or "Set" a value, gets called if it exists when the core functionality of the program tries to set a value. This helps in enhancing the flexibility of the program as it will be able to handle a more diverse set of scenarios.

  • Check Before Setting Attribute Values This update adds a verification step before assigning a value to an attribute - it checks if the attribute exists in the first place. This significantly boosts the stability of the program as we prevent potential errors that might occur when trying to assign values to non-existent attributes.

what-the-diff[bot] avatar Mar 30 '24 06:03 what-the-diff[bot]

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 88.51%. Comparing base (d2fa237) to head (a0af203). Report is 2 commits behind head on master.

Files Patch % Lines
src/BaseActiveRecordTrait.php 50.00% 2 Missing :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #298      +/-   ##
============================================
- Coverage     88.63%   88.51%   -0.12%     
- Complexity      575      576       +1     
============================================
  Files             7        7              
  Lines          1302     1306       +4     
============================================
+ Hits           1154     1156       +2     
- Misses          148      150       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Mar 30 '24 06:03 codecov[bot]

Try it now, should work.

Tigrov avatar May 23 '24 02:05 Tigrov