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

[Bug]: Export FromQuery double join statements in query. #4133

Open
1 task done
Max-Hutschenreiter opened this issue May 17, 2024 · 1 comment
Open
1 task done

[Bug]: Export FromQuery double join statements in query. #4133

Max-Hutschenreiter opened this issue May 17, 2024 · 1 comment
Labels

Comments

@Max-Hutschenreiter
Copy link

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.55

What version of Laravel are you using?

v10.48.7

What version of PHP are you using?

8.3.7

Describe your issue

I wrote a class implementing FromQuery and With Headings to use Exportable.

I used the __constructor to pass a Query from outside, which I am referencing in the query method.
This is working fine. At the moment, when I add a join to the query method, it adds it twice.
If I am not passing the query over the constructor, it's working. If I am adding the joins outside and than pass it its also working.

Call of the class
$query = Review::query(); return (new ExcelReviewExport($query))->download('reviews.xlsx');

`class ExcelReviewExport implements FromQuery, WithHeadings
{
use Exportable;

public $query;

public function __construct($query)
{
    $this->query = $query;
}

public function query(){
    return $this->query
    ->select(['id'])
    ->join("products", "reviews.product_id", '=', "products.id");
}`

This is not stated in the documentation and maybe was never supposed to be used like this, but it would be nice if it worked. I will add the joins as a workaround outside of the class, so this is really low prior for me.

Thanks for the great work on this Package!

How can the issue be reproduced?

Create an ExcelExport Class with FromQuery.
Pass the query over to the constructor.
Add a join in the query method to the passed query.

What should be the expected behaviour?

Adding joins only once.

@sinnbeck
Copy link

I would expect that it is running the query() twice and as laravels query builder is using classes, it will add the join twice as well.

So try doing a clone

 public function query(){
    return $this->query
    ->clone()
    ->select(['id'])
    ->join("products", "reviews.product_id", '=', "products.id");
}`

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

No branches or pull requests

2 participants