File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -549,6 +549,31 @@ public function relation(string $name): ActiveRecordInterface|array|null
549549 return $ this ->retrieveRelation ($ name );
550550 }
551551
552+ /**
553+ * @inheritdoc
554+ *
555+ * Relations can be defined using {@see hasOne()} and {@see hasMany()} methods. For example:
556+ *
557+ * ```php
558+ * public function relationQuery(string $name): ActiveQueryInterface
559+ * {
560+ * return match ($name) {
561+ * 'orders' => $this->hasMany(Order::class, ['customer_id' => 'id']),
562+ * 'country' => $this->hasOne(Country::class, ['id' => 'country_id']),
563+ * default => parent::relationQuery($name),
564+ * };
565+ * }
566+ * ```
567+ */
568+ public function relationQuery (string $ name , bool $ throwException = true ): ActiveQueryInterface |null
569+ {
570+ if (!$ throwException ) {
571+ return null ;
572+ }
573+
574+ throw new InvalidArgumentException (static ::class . ' has no relation named " ' . $ name . '". ' );
575+ }
576+
552577 public function resetRelation (string $ name ): void
553578 {
554579 foreach ($ this ->relationsDependencies as &$ relationNames ) {
You can’t perform that action at this time.
0 commit comments