Skip to content

Bug in endedReserves #5

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

Open
robertogallea opened this issue Jan 23, 2025 · 0 comments
Open

Bug in endedReserves #5

robertogallea opened this issue Jan 23, 2025 · 0 comments

Comments

@robertogallea
Copy link

Hi @shayan-yousefi !

The current implementation has a bug in the loading of endedReserves. Indeed, the current code

    public function endedReserves(): MorphMany
    {
        return $this->reserves()->whereDate('end_reserve_date', '<', now())->orWhere(function ($query) {
            $query->whereDate('end_reserve_date', '=', now())->whereTime('end_reserve_time', '<=', now());
        })->with(['customer', 'reservable']);
    }

produces the query

SELECT *
FROM   `reserves`
WHERE  `reserves`.`customer_type` = ?
       AND `reserves`.`customer_id` = ?
       AND `reserves`.`customer_id` IS NOT NULL
       AND Date(`end_reserve_date`) < ?
        OR ( Date(`end_reserve_date`) = ?
             AND Time(`end_reserve_time`) <= ? ) 

which is wrong (it loads today reserves with past time without regards of any other condition.

The correct query should be

SELECT *
FROM   `reserves`
WHERE  `reserves`.`customer_type` = ?
       AND `reserves`.`customer_id` = ?
       AND `reserves`.`customer_id` IS NOT NULL
       AND ( Date(`end_reserve_date`) < ?
              OR ( Date(`end_reserve_date`) = ?
                   AND Time(`end_reserve_time`) <= ? ) ) 

I'm making a PR which solves the issue.

Thank you.

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

No branches or pull requests

1 participant