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

[5.5] Remove the between operator in basic where clause #22182

Merged
merged 1 commit into from
Nov 23, 2017

Conversation

themsaid
Copy link
Member

It's currently not working and generating wrong sql:

\App\User::where('created_at', 'between', ['2017-01-01', '2017-01-30'])->get();

Will generate

select * from users where created_at between 2017-01-01

Verified

This commit was signed with the committer’s verified signature.
newhoggy John Ky
@ntzm
Copy link
Contributor

ntzm commented Nov 23, 2017

Should it not just be fixed?

@themsaid
Copy link
Member Author

Like whereIn I believe whereBetween should be used instead.

@aleksandrlat
Copy link

aleksandrlat commented Nov 23, 2017

In Illuminate\Database\Query\Builder::where something like

if ($operator == 'between') {
    return $this->whereBetween($column, $value, $boolean);
}

would be useful in case of array of wheres

Model::where([
    ['active', 1],
    ['created_at', 'between', ['2017-01-01', '2017-01-07']],
]);

I know I can use '<=', '>=' operators instead of 'between' in this case but still.

@themsaid
Copy link
Member Author

@aleksandrlat I'm ok with both ways, @taylorotwell what do you think?

@taylorotwell
Copy link
Member

I kind of agree people should just use whereBetween?

@taylorotwell taylorotwell reopened this Nov 23, 2017
@taylorotwell taylorotwell merged commit 4cb36d0 into laravel:5.5 Nov 23, 2017
@JosephSilber
Copy link
Contributor

JosephSilber commented Dec 8, 2017

@themsaid this broke my code. Took me a few hours to track it down 😢

I have a join with a BETWEEN where it checks if a given column's value is between two other columns:

$join->on('b.lft', 'BETWEEN', DB::raw('a.lft AND a.rgt'))

This is used to query a nested set table.


This used to generate:

join b on `b`.`lft` BETWEEN a.lft AND a.rgt

but now it generates:

join b on `b`.`lft` = `BETWEEN`

...which obviously leads to this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BETWEEN' in 'on clause'

I haven't touched this code in years, and it has worked flawlessly. This change broke it 😞

@AidasK
Copy link

AidasK commented Jan 16, 2018

Thanks for a breaking change in a stable version 👍

izazueta pushed a commit to izazueta/framework that referenced this pull request Apr 22, 2020
* We need this to use the operator in a having clause.
* On Laravel 5.5, this operator was removed by laravel#22182
* On Laravel 5.7 there is a new havingBetween method that we can use instead laravel#26758
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.

None yet

6 participants