Skip to content

Commit

Permalink
add missing behaviors to ngrest find
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jan 4, 2023
1 parent cdf397c commit 8681135
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/ngrest/base/NgRestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function extraFields()
* As behavior methods can be access from the inner class, use full functions can be used inside the active query.
* It also enables the option to share standardized behaviors with functions (conditions), for example a soft delete condition.
*
* A behavior example
* A behavior example:
*
* ```php
* class MySuperBehavioir extends yii\base\Behavior
Expand All @@ -130,7 +130,7 @@ public function extraFields()
*
* After attaching this behavior, it can be used like `MyModel::find()->active()->one()`.
*
* > Whenever possible, directly create a custom Active Query, as it provices full IDE support. The behavior
* > Whenever possible, directly create a custom Active Query, as it provides full IDE support. The behavior
* > does not, the example above will even show an IDE error because the mmethod `andWhere()` does not exsist
* > in the yii\base\Behavior class.
*
Expand All @@ -139,14 +139,19 @@ public function extraFields()
* the behavior class or an array of the following structure:
*
* ```php
* 'behaviorName' => [
* 'class' => 'BehaviorClass',
* 'property1' => 'value1',
* 'property2' => 'value2',
* ]
* public static function findActiveQueryBehaviors()
* {
* return [
* 'behaviorName' => [
* 'class' => 'BehaviorClass',
* 'property1' => 'value1',
* 'property2' => 'value2',
* ]
* ]
* }
* ```
*
* @see {{\yii\base\Component::behaviors}}
*
* @return array
* @since 3.4.0
*/
Expand Down Expand Up @@ -541,7 +546,13 @@ public function ngRestRelations()
*/
public static function ngRestFind()
{
return new NgRestActiveQuery(static::class);
$config = [];

foreach (static::findActiveQueryBehaviors() as $name => $class) {
$config['as ' . $name] = $class;
}

return new NgRestActiveQuery(static::class, $config);
}

/**
Expand Down

0 comments on commit 8681135

Please sign in to comment.