Last active
August 13, 2017 11:35
-
-
Save nadar/ae6aeefcad4d590848faca35a718cb28 to your computer and use it in GitHub Desktop.
Dynamic Detach After Find Event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Model | |
class MyText extends \yii\db\ActiveRecord | |
{ | |
public $unserialize = true; | |
public function behaviors() | |
{ | |
$behaviors = [] | |
if ($this->unserialize) { | |
'unserializejson' => [ | |
'class' => JsonUnserializeBehavior::class, | |
'fields' => ['text'], | |
] | |
} | |
return $behaviors; | |
} | |
} | |
// How to dynamic disable: | |
$model = MyText::findOne(1); // already triggered | |
// how to provide object context variable within static call. | |
// The only possibility would be to provide ActiveQuery function which binds parameters to ActiveRecord Like: | |
$model = MyText::find()->where(['id' => 1])->bind(['unserialize' => false])->one(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment