Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[5.2] Add whereColumn clause#13549

Merged
taylorotwell merged 2 commits into
laravel:5.2from
acasar:where-column
May 15, 2016
Merged

[5.2] Add whereColumn clause#13549
taylorotwell merged 2 commits into
laravel:5.2from
acasar:where-column

Conversation

@acasar
Copy link
Copy Markdown
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
Copy Markdown
Contributor

vlakoff commented May 16, 2016

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

@vlakoff
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

vlakoff commented May 16, 2016

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

@JosephSilber
Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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