Giter Site home page Giter Site logo

Comments (12)

mootensai avatar mootensai commented on May 14, 2024

Can you show me the error?

from yii2-enhanced-gii.

RGTimothy avatar RGTimothy commented on May 14, 2024

These 2 images below are the error.

moo1

moo2

from yii2-enhanced-gii.

mootensai avatar mootensai commented on May 14, 2024

Please show me the full error, generated models, & SQLs..

from yii2-enhanced-gii.

mootensai avatar mootensai commented on May 14, 2024

this is because you don't setup the foreign key of table_a_id column at table_b

from yii2-enhanced-gii.

iurijacob avatar iurijacob commented on May 14, 2024

I'm having the same issue. This occurs when your tables have composite names, like my_table1.
So, for example, in crud\Generator.php in method generateGridViewFieldIndex, about line 941 you have:

$modelRel = $rel[2] ? Inflector::pluralize($rel[3]) : $rel[3];
$output = "[
    'attribute' => '$attribute',
    'label' => " . $this->generateString(ucwords(Inflector::humanize($rel[5]))) . ",
    'value' => function(\$model){
        return \$model->$modelRel->$labelCol;
    },
    'filterType' => GridView::FILTER_SELECT2,
    'filter' => \\yii\\helpers\\ArrayHelper::map(\\$this->nsModel\\$rel[1]::find()->asArray()->all(), '$rel[4]', '$labelCol'),
    'filterWidgetOptions' => [
        'pluginOptions' => ['allowClear' => true],
    ],
    'filterInputOptions' => ['placeholder' => '$humanize', 'id' => '$id']
],\n";
return $output;

Note that $modeRelat line 941 is set to pluralize or the normal attribute pattern (with underscore separating words). But at line 946 it should be in variablize pattern (with camelcase separating words).

In the case above we can fix the issue by changing the line 946 to:

$modelRel = $rel[2] ? Inflector::pluralize($rel[3]) : Inflector::variablize($rel[3]);

The same can be done in generateDetailViewField method, about line 826, that get fixed by replacing these lines:

$output = "[
'attribute' => '$rel[3].$labelCol',
'label' => " . $this->generateString(ucwords(Inflector::humanize($rel[5]))) . ",

with these lines:

$modelRel = $rel[2] ? Inflector::pluralize($rel[3]) : Inflector::variablize($rel[3]);
$output = "[
'attribute' => '$modelRel.$labelCol',
'label' => " . $this->generateString(ucwords(Inflector::humanize($rel[5]))) . ",

I'm testing it by now, but it seems that the issue is cleared.

from yii2-enhanced-gii.

mootensai avatar mootensai commented on May 14, 2024
                                                                                  Please test @dev version‎. Is dev version is still generate the same error?

from yii2-enhanced-gii.

iurijacob avatar iurijacob commented on May 14, 2024

Yes. I'm using the @dev version.

from yii2-enhanced-gii.

mootensai avatar mootensai commented on May 14, 2024

from yii2-enhanced-gii.

iurijacob avatar iurijacob commented on May 14, 2024

Yes, the error still occurs in @dev version. You have to fix the code mentioned above in order to fix the issue.

from yii2-enhanced-gii.

mootensai avatar mootensai commented on May 14, 2024

could you give me your sqldump? I've tested @dev version with http://downloads.mysql.com/docs/sakila-db.zip database. And when I generate actors, film-actors, and films (many-many relationship / film-actors have composite pk), it's fine.

from yii2-enhanced-gii.

iurijacob avatar iurijacob commented on May 14, 2024

Great!! it seems to be working now.
Although it still stucks in self-referenced tables. But everything else is just fine.

from yii2-enhanced-gii.

mootensai avatar mootensai commented on May 14, 2024

from yii2-enhanced-gii.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.