laravel-idea / plugin

Laravel Idea plugin for PhpStorm
https://laravel-idea.com/
160 stars 7 forks source link

[Bug]: Table not found when using SQL views (rather than tables) for a model #942

Open ryanmortier opened 4 months ago

ryanmortier commented 4 months ago

Bug description

CleanShot 2024-03-01 at 15 04 53

In my app I sometimes model sql views rather than tables.

Laravel Idea always warns about not finding the table (understandable since it's a view). Is there a way to have Laravel Idea understand this?

Plugin version

8.1.2.233

Operating system

MacOS

Steps to reproduce

No response

Relevant log output

No response

adelf commented 4 months ago

Do you have a connection for your database in PhpStorm's Database tab? IF yes, you can try to main menu > Laravel > Helper Code Parameters... and choose Fetch data from Connection. And don't forget "Also fetch from migrations". This might help.

BTW, how do you describe the view in your migrations?

ryanmortier commented 4 months ago

Do you have a connection for your database in PhpStorm's Database tab? IF yes, you can try to main menu > Laravel > Helper Code Parameters... and choose Fetch data from Connection. And don't forget "Also fetch from migrations". This might help.

I just gave this a try, same problem. I'm wondering if it's because I'm using SQL Server schemas and the table (view) it's failing to find isn't on the default schema?

edit: it doesn't seem like the schema matters. I tried moving it to the default schema but same problem.

BTW, how do you describe the view in your migrations?

public function up(): void
{
    $database_agtech = config('database.connections.sqlsrv.database_agtech');

    $query = <<<SQL
        CREATE OR ALTER VIEW [crm].[accounts]
        AS
        SELECT
            LOWER([s1_name_and_address].[name_and_address_id]) AS [id],
            [s1_name_and_address].[name_and_address_id],
            [s1_name_and_address].[short_name],
            TRIM([s1_name_and_address].[full_name]) AS [name],
            TRIM([s1_name_and_address].[long_name]) AS [long_name],
            [s1_name_and_address].[address_line_1],
            [s1_name_and_address].[address_line_2],
            [s1_name_and_address].[city],
            [s1_name_and_address].[state_province_code],
            [s1_name_and_address].[state_province_name],
            [s1_name_and_address].[country_code],
            [s1_name_and_address].[zip_postal_code],
            [s1_name_and_address].[inactive_flag],
            [s1_name_and_address].[add_date],
            [s1_name_and_address].[change_date]
        FROM
            [{$database_agtech}].[dba].[s1_name_and_address] WITH (NOLOCK)
        WHERE
            [s1_name_and_address].[grain_customer_flag] = 'Y'
            AND [s1_name_and_address].[plc_flag] = 'N'
            AND [s1_name_and_address].[sales_rep_flag] = 'N'
            AND [s1_name_and_address].[agency_flag] = 'N'
            AND [s1_name_and_address].[bank_flag] = 'N';
    SQL;

    DB::statement($query);
}
superdejooo commented 2 months ago

Same issue here. Did you find any workaround @ryanmortier ?

ryanmortier commented 2 months ago

No, just dealing with the warnings for now.