Skip to content

No way to mark an array of $ref as a non-DB relation #121

Description

@siggi-k

A single $ref can already be declared as "not a foreign key" and then generates an abstract
getter the app implements itself:

document:
  allOf:
    - $ref: '#/components/schemas/Document'
    - x-db-type: false
abstract public function getDocument(): \yii\db\ActiveQuery;

For type: array there is no spec form that reaches this.

Wanted

One of these inputs should work (or both, whichever is cheaper):

# form 1
customFieldLeads:
  type: array
  readOnly: true
  x-db-type: false
  items:
    $ref: '#/components/schemas/Lead'
# form 2
customFieldLeads:
  allOf:
    - type: array
      readOnly: true
      items:
        $ref: '#/components/schemas/Lead'
    - x-db-type: false

The output must be identical to the plain form without the marker (property type, transformer
include, client relations() entry), with two differences: no DB column, and

-    public function getCustomFieldLeads()
-    {
-        return $this->hasMany(\common\models\Lead::class, ['order_id' => 'id'])->inverseOf('order');
-    }
+    abstract public function getCustomFieldLeads(): \yii\db\ActiveQuery;

Now

Form 1 throws:

InvalidDefinitionException: References not supported for virtual attributes
src/lib/AttributeResolver.php:306

Form 2 loses the whole inner schema. getAttr() reads the top level only, and the allOf loop in
PropertySchema::__construct() applies x-db-type: false only when the allOf holds a $ref.
The property degenerates to string and gets trim/string rules plus a real text column.

Root cause for both: initItemsReference() sets isNonDbReference only when the referenced
schema
is non-DB (PropertySchema.php:217-219), never from the property's own x-db-type: false.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions