1414use cebe \yii2openapi \lib \items \DbModel ;
1515use cebe \yii2openapi \lib \items \JunctionSchemas ;
1616use cebe \yii2openapi \lib \items \ManyToManyRelation ;
17+ use cebe \yii2openapi \lib \items \NonDbRelation ;
1718use cebe \yii2openapi \lib \openapi \ComponentSchema ;
1819use cebe \yii2openapi \lib \openapi \PropertySchema ;
1920use Yii ;
@@ -35,7 +36,10 @@ class AttributeResolver
3536 * @var AttributeRelation[]|array
3637 */
3738 private $ relations = [];
38-
39+ /**
40+ * @var NonDbRelation[]|array
41+ */
42+ private $ nonDbRelations = [];
3943 /**
4044 * @var ManyToManyRelation[]|array
4145 */
@@ -102,6 +106,7 @@ public function resolve():DbModel
102106 'description ' => $ this ->schema ->getDescription (),
103107 'attributes ' => $ this ->attributes ,
104108 'relations ' => $ this ->relations ,
109+ 'nonDbRelations ' => $ this ->nonDbRelations ,
105110 'many2many ' => $ this ->many2many ,
106111 'indexes ' => $ this ->prepareIndexes ($ this ->schema ->getIndexes ()),
107112 //For valid primary keys for junction tables
@@ -203,6 +208,17 @@ protected function resolveProperty(PropertySchema $property, bool $isRequired):v
203208 if ($ property ->isVirtual ()) {
204209 throw new InvalidDefinitionException ('References not supported for virtual attributes ' );
205210 }
211+
212+ if ($ property ->isNonDbReference ()) {
213+ $ attribute ->asNonDbReference ($ property ->getRefClassName ());
214+ $ relation = Yii::createObject (
215+ NonDbRelation::class,
216+ [$ property ->getName (), $ property ->getRefClassName (), NonDbRelation::HAS_ONE ]
217+ );
218+
219+ $ this ->nonDbRelations [$ property ->getName ()] = $ relation ;
220+ return ;
221+ }
206222
207223 $ fkProperty = $ property ->getTargetProperty ();
208224 if (!$ fkProperty && !$ property ->getRefSchema ()->isObjectSchema ()) {
@@ -249,6 +265,18 @@ protected function resolveProperty(PropertySchema $property, bool $isRequired):v
249265 if ($ property ->isVirtual ()) {
250266 throw new InvalidDefinitionException ('References not supported for virtual attributes ' );
251267 }
268+
269+ if ($ property ->isNonDbReference ()) {
270+ $ attribute ->asNonDbReference ($ property ->getRefClassName ());
271+ $ relation = Yii::createObject (
272+ NonDbRelation::class,
273+ [$ property ->getName (), $ property ->getRefClassName (), NonDbRelation::HAS_MANY ]
274+ );
275+
276+ $ this ->nonDbRelations [$ property ->getName ()] = $ relation ;
277+ return ;
278+ }
279+
252280 if ($ property ->isRefPointerToSelf ()) {
253281 $ relatedClassName = $ property ->getRefClassName ();
254282 $ attribute ->setPhpType ($ relatedClassName . '[] ' );
0 commit comments