Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Resolve all TODOs in code #180

Open
Open
@SOHELAHMED7

Description

@SOHELAHMED7

Example:

src/lib/SchemaToDatabase.php

public function prepareModels():array
    {
        $models = [];
        $openApi = $this->config->getOpenApi();
        $junctions = $this->findJunctionSchemas();
        foreach ($openApi->components->schemas as $schemaName => $openApiSchema) {
            $schema = Yii::createObject(ComponentSchema::class, [$openApiSchema, $schemaName]);

            if (!$this->canGenerateModel($schemaName, $schema)) {
                continue;
            }
            if ($junctions->isJunctionSchema($schemaName)) {
                $schemaName = $junctions->trimPrefix($schemaName);
            }
            /** @var \cebe\yii2openapi\lib\AttributeResolver $resolver */
            $resolver = Yii::createObject(AttributeResolver::class, [$schemaName, $schema, $junctions, $this->config]);
            $models[$schemaName] = $resolver->resolve();
        }
        foreach ($models as  $model) {
            foreach ($model->many2many as $relation) {
                if (isset($models[$relation->viaModelName])) {
                    $relation->hasViaModel = true;
                }
                $relation->pkAttribute = $model->getPkAttribute();
                $relation->relatedPkAttribute = $models[$relation->relatedSchemaName]->getPkAttribute();
            }
        }

        // TODO generate inverse relations <------------ this one

        return $models;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions