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.2] Add whereColumn clause #13549

Merged
merged 2 commits into from
May 15, 2016
Merged

[5.2] Add whereColumn clause #13549

merged 2 commits into from
May 15, 2016

Conversation

acasar
Copy link
Contributor

@acasar acasar commented May 13, 2016

If we want to compare two columns inside a where clause, we now need to write a raw expression:

User::whereRaw('`first_name` = `last_name`');

But with this PR we can use a new whereColumn method:

User::whereColumn('first_name', 'last_name');

As with normal where clauses, array conditions can be passed as well:

User::whereColumn([
    ['first_name', 'last_name'],
    ['updated_at', '>', 'created_at']
]);

@taylorotwell taylorotwell merged commit ca86102 into laravel:5.2 May 15, 2016
@vlakoff
Copy link
Contributor

vlakoff commented May 16, 2016

whereColumn doesn't really describe what it does. Maybe something like whereEqualColumns?

@vlakoff
Copy link
Contributor

vlakoff commented May 16, 2016

Ah, but it's not only about egality. So maybe whereCompareColumns? I can't think of a better name…

@acasar
Copy link
Contributor Author

acasar commented May 16, 2016

It's supposed to function like a sentence: "where column first_name equals (to the column) last_name".

@vlakoff
Copy link
Contributor

vlakoff commented May 16, 2016

It's much clearer, once having kept this in mind.

@JosephSilber
Copy link
Member

For a regular where you can also pass an array, but there it's an associative array. Having an associative array means you can't specify the operator, but I think that's fair; if you need different operators, call the method multiple times.

Whatever we do, it should be consistent between these two methods.

@acasar
Copy link
Contributor Author

acasar commented May 17, 2016

A while ago a regular where was updated to allow for the syntax I mentioned above. Since whereColumn is using the same array parsing logic as the normal where, it's entirely consistant.

@JosephSilber
Copy link
Member

Oh you're right. Didn't know about that.

Learn something new every day 💯

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.

4 participants