File tree Expand file tree Collapse file tree 3 files changed +45
-5
lines changed Expand file tree Collapse file tree 3 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use yii \helpers \ArrayHelper ;
6
6
use yii \db \ActiveRecord as BaseModel ;
7
+ use indigerd \embedded \behavior \HydrateCollectionBehavior ;
7
8
8
9
class ActiveRecord extends BaseModel
9
10
{
10
11
public function setAttributes ($ values , $ safeOnly = true )
11
12
{
12
13
$ this ->trigger (Model::EVENT_BEFORE_POPULATE );
13
- $ oldValues = $ this ->getAttributes (\array_keys ($ values ));
14
+ $ keys = [];
15
+ foreach ($ values as $ key => $ value ) {
16
+ if ($ this ->hasAttribute ($ key )) {
17
+ $ keys [] = $ key ;
18
+ }
19
+ }
20
+ $ oldValues = $ this ->getAttributes ($ keys );
21
+ $ behaviors = $ this ->getBehaviors ();
22
+ foreach ($ behaviors as $ behavior ) {
23
+ if ($ behavior instanceof HydrateCollectionBehavior and isset ($ values [$ behavior ->attribute ])) {
24
+ unset($ oldValues [$ behavior ->attribute ]);
25
+ }
26
+ }
14
27
$ values = ArrayHelper::merge ($ oldValues , $ values );
15
28
parent ::setAttributes ($ values , $ safeOnly );
16
29
$ this ->trigger (Model::EVENT_AFTER_POPULATE );
Original file line number Diff line number Diff line change 4
4
5
5
use yii \helpers \ArrayHelper ;
6
6
use yii \base \Model as BaseModel ;
7
+ use indigerd \embedded \behavior \HydrateCollectionBehavior ;
7
8
8
9
class Model extends BaseModel
9
10
{
@@ -12,10 +13,23 @@ class Model extends BaseModel
12
13
13
14
public function setAttributes ($ values , $ safeOnly = true )
14
15
{
15
- $ this ->trigger (self ::EVENT_BEFORE_POPULATE );
16
- $ oldValues = $ this ->getAttributes (\array_keys ($ values ));
16
+ $ this ->trigger (Model::EVENT_BEFORE_POPULATE );
17
+ $ keys = [];
18
+ $ reflection = new \ReflectionClass ($ this );
19
+ foreach ($ values as $ key => $ value ) {
20
+ if ($ reflection ->hasProperty ($ key )) {
21
+ $ keys [] = $ key ;
22
+ }
23
+ }
24
+ $ oldValues = $ this ->getAttributes ($ keys );
25
+ $ behaviors = $ this ->getBehaviors ();
26
+ foreach ($ behaviors as $ behavior ) {
27
+ if ($ behavior instanceof HydrateCollectionBehavior and isset ($ values [$ behavior ->attribute ])) {
28
+ unset($ oldValues [$ behavior ->attribute ]);
29
+ }
30
+ }
17
31
$ values = ArrayHelper::merge ($ oldValues , $ values );
18
32
parent ::setAttributes ($ values , $ safeOnly );
19
- $ this ->trigger (self ::EVENT_AFTER_POPULATE );
33
+ $ this ->trigger (Model ::EVENT_AFTER_POPULATE );
20
34
}
21
35
}
Original file line number Diff line number Diff line change 5
5
use yii \helpers \ArrayHelper ;
6
6
use yii \mongodb \ActiveRecord as BaseModel ;
7
7
use indigerd \embedded \model \Model ;
8
+ use indigerd \embedded \behavior \HydrateCollectionBehavior ;
8
9
9
10
class ActiveRecord extends BaseModel
10
11
{
11
12
public function setAttributes ($ values , $ safeOnly = true )
12
13
{
13
14
$ this ->trigger (Model::EVENT_BEFORE_POPULATE );
14
- $ oldValues = $ this ->getAttributes (\array_keys ($ values ));
15
+ $ keys = [];
16
+ foreach ($ values as $ key => $ value ) {
17
+ if ($ this ->hasAttribute ($ key )) {
18
+ $ keys [] = $ key ;
19
+ }
20
+ }
21
+ $ oldValues = $ this ->getAttributes ($ keys );
22
+ $ behaviors = $ this ->getBehaviors ();
23
+ foreach ($ behaviors as $ behavior ) {
24
+ if ($ behavior instanceof HydrateCollectionBehavior and isset ($ values [$ behavior ->attribute ])) {
25
+ unset($ oldValues [$ behavior ->attribute ]);
26
+ }
27
+ }
15
28
$ values = ArrayHelper::merge ($ oldValues , $ values );
16
29
parent ::setAttributes ($ values , $ safeOnly );
17
30
$ this ->trigger (Model::EVENT_AFTER_POPULATE );
You can’t perform that action at this time.
0 commit comments