krlove / eloquent-model-generator

Eloquent Model Generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't generate a model from a view

italba opened this issue · comments

It can be easily done modifying the name check in ExistenceCheckerProcessor

public function process(EloquentModel $model, Config $config)
{
    $schemaManager = $this->databaseManager->connection($config->get('connection'))->getDoctrineSchemaManager();
    $prefix = $this->databaseManager->connection($config->get('connection'))->getTablePrefix();

    $currName = array($prefix . $model->getTableName());
    if (!$schemaManager->tablesExist($currName)) {
        if (!$this->viewsExist($currName, $schemaManager->listViews())) {
            throw new GeneratorException(sprintf('Table/view %s does not exist', $prefix . $model->getTableName()));
        }
    }
}

private function viewsExist($currView, $Names){
    $listViews = array();
    foreach ($Names as $currName){
        $listViews[]= strtolower($currName->getName());
    }
    $viewNames = array_map('strtolower', (array) $currView);
    return count($viewNames) === count(array_intersect($viewNames, $listViews));
}