Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table name with primary key for selected items export #1843

Open
wants to merge 1 commit into
base: 6.x
Choose a base branch
from

Conversation

eafarooqi
Copy link
Contributor

⚡ PowerGrid - Pull Request

  • Bug fix
  • Enhancement
  • New feature
  • Breaking change

Description

With a complex query as datasource with joins, when exporting selected items you get an ambiguous primary key error. Table name is missing in the where query.

Related Issue(s): #1841

Documentation

This PR requires Documentation update?

  • Yes
  • No
  • I have already submitted a Documentation pull request.

@luanfreitasdev
Copy link
Member

What do you think of this solution? We could create a method inside the component and use it in ExportableJob as well.

$property = fn (string $property) => Support\Str::of($processDataSource->component->{$property})->contains('.')
            ? $processDataSource->component->{$property}
            : $currentTable . '.' . $processDataSource->component->{$property};

        $results = $processDataSource->component->datasource()
            ->where(
                fn ($query) => Builder::make($query, $this)
                    ->filterContains()
                    ->filter()
            )
            ->when($filtered, function ($query, $filtered) use ($property) {
                return $query->whereIn($property('primaryKey'), $filtered);
            })
            ->orderBy($property('sortField'), $processDataSource->component->sortDirection)
            ->get();

@eafarooqi
Copy link
Contributor Author

What do you think of this solution? We could create a method inside the component and use it in ExportableJob as well.

$property = fn (string $property) => Support\Str::of($processDataSource->component->{$property})->contains('.')
            ? $processDataSource->component->{$property}
            : $currentTable . '.' . $processDataSource->component->{$property};

        $results = $processDataSource->component->datasource()
            ->where(
                fn ($query) => Builder::make($query, $this)
                    ->filterContains()
                    ->filter()
            )
            ->when($filtered, function ($query, $filtered) use ($property) {
                return $query->whereIn($property('primaryKey'), $filtered);
            })
            ->orderBy($property('sortField'), $processDataSource->component->sortDirection)
            ->get();

Totally agree! that's better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants