luyadev / luya-module-admin

Administration base module for all LUYA admin modules
https://luya.io
MIT License
48 stars 56 forks source link

SelectRelationActiveQuery plugin is not working properly in a model with pool #703

Open jettero777 opened 2 years ago

jettero777 commented 2 years ago

What steps will reproduce the problem?

plugin SelectRelationActiveQuery used in a model with pool api

What is the expected result?

should be shown a button to select related records

What do you get instead? (A Screenshot can help us a lot!)

there is no button to choose records if plugin used in a model without pool, then the button is visible and works as expected

Untitled-1

Additional infos

Q A
LUYA Version luya-module-admin 4.2.0
PHP Version 8.1
Platform NGINX
Operating system Linux
nadar commented 2 years ago

Thanks for the report, i'll check that. Could you please post me your ngRestConfig parts, so we can easy reproduce?

jettero777 commented 2 years ago

Hi @nadar sure, here simplified config for testing

<?php
namespace app\modules\test\models;

use luya\admin\ngrest\base\NgRestModel;

class Test extends NgRestModel
{
    public static function tableName()
    {
        return 'test';
    }

    public static function ngRestApiEndpoint()
    {
        return 'api-test';
    }

    public function ngRestAttributeTypes()
    {
        return [
            'is_active' => [
                'toggleStatus',
                'initValue' => 0,
            ],
            'user_id' => [
                'SelectRelationActiveQuery',
                'query' => $this->getUser(),
                'labelField' => 'id',
            ],
        ];
    }

    public function rules()
    {
        return [
            [['is_active', 'user_id'], 'safe'],
        ];
    }

    public function ngRestScopes()
    {
        return [
            [['list', 'create', 'update'], ['is_active', 'user_id']],
        ];
    }

    public function ngRestPools()
    {
        return [
            'inactive' => ['is_active' => 0],
            'active' => ['is_active' => 1],
        ];
    }

    public function getUser()
    {
        return $this->hasOne(
            User::class, ['id' => 'user_id']
        );
    }
}
    public function getMenu()
    {
        return (new AdminMenuBuilder($this))
            ->node('Test', 'person')
                ->group('test')
                    ->itemApi('Test1', 'test/test/index', 'person', 'api-test')
                    ->itemPoolApi('Test2', 'test/test/index', 'person', 'api-test', 'inactive')
                    ->itemPoolApi('Test3', 'test/test/index', 'person', 'api-test', 'active');
    }