phalcon / phalcon-devtools

Phalcon Developer Tools
https://docs.phalcon.io/latest/en/devtools
Other
1.33k stars 630 forks source link

Create one model take too long with Postgre #1319

Open quickdunk opened 5 years ago

quickdunk commented 5 years ago

Hi, I want to create one model using phalcon tools 3.4.0 with this command:

phalcon model seg_usuarios --namespace="App\Models" --get-set

In this particular case the database have many tables (more than 700) and when I try to execute take too long, so I explored the code and found the same issue reported and solved before: https://github.com/phalcon/phalcon-devtools/issues/821

I expected the model was created without any relationship unless I specified by command line.

I solved modifying: Phalcon\Builder\Model.php

// line 212
$referenceList = $this->getReferenceList($schema, $table, $db);

// function getReferenceList
/**
     * Get reference list from option
     *
     * @param string $schema
     * @param string $table
     * @param Pdo $db
     * @return array
     */
    protected function getReferenceList($schema, $table, Pdo $db)
    {
        if ($this->modelOptions->hasOption('referenceList')) {
            return $this->modelOptions->getOption('referenceList');
        }

        $referenceList = [];

        if (isset($referenceList[$table])) {
            $referenceList = $referenceList[$table];
        } else {
            $referenceList[$table] = $db->describeReferences($table, $schema);
        }

        return $referenceList;
    }

And I found the 'reference List' is not send by command line, so the if clause never return that value.

Details

Directive => Local Value => Master Value phalcon.db.escape_identifiers => On => On phalcon.db.force_casting => Off => Off phalcon.orm.events => On => On phalcon.orm.virtual_foreign_keys => On => On phalcon.orm.column_renaming => On => On phalcon.orm.not_null_validations => On => On phalcon.orm.exception_on_failed_save => Off => Off phalcon.orm.enable_literals => On => On phalcon.orm.late_state_binding => Off => Off phalcon.orm.enable_implicit_joins => On => On phalcon.orm.cast_on_hydrate => Off => Off phalcon.orm.ignore_unknown_columns => Off => Off phalcon.orm.update_snapshot_on_save => On => On phalcon.orm.disable_assign_setters => Off => Off`

Jeckerson commented 3 years ago

Problem in Phalcon Adapter.