-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Sub-query support in from() and join() #5577
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
Sub-query support in from() and join() #5577
Conversation
that looks nice |
I'd like to see a sample using |
@@ -274,6 +281,13 @@ public function from($table) | |||
*/ | |||
public function join($table, $one, $operator = null, $two = null, $type = 'inner', $where = false) | |||
{ | |||
if (is_array($table) && count($table) === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Braces for control statements should be on a new line please.
@GrahamCampbell: Braces fixed & squashed, cheers @RSully: not sure what you mean? |
@JamShady I was thinking it might be over complicating the test by using a |
@RSully, I see. I didn't write it so can't take the credit, I took it from @jarredholman |
It was to test the specific use case I wanted this feature for. Being able to define expressions as columns in the subquery and then using that column in a select or where in the outer query. It makes writing reusable table/grid ajax code much easier. Does raw really make it more complicated? Its pretty much required for anything but the most basic operations. |
Right but this test isn't about raw, it's just about from/join. My goal would be to remove anything that is unnecessary to keep the test as pure as possible. |
using and array of size one to trigger this behavior seems a bit strange. It would be a lot simpler and clearer to add |
@@ -256,8 +257,15 @@ public function distinct() | |||
*/ | |||
public function from($table) | |||
{ | |||
$this->from = $table; | |||
if (is_array($table) && count($table) === 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also indicate array
type in @param
of this parameter in DocBlock.
Are sub selects like this supported in a sql dialects? |
@bostanio Good suggestion, I don't see why we can't have both. Would like to see what @taylorotwell has to say before implementing it though. Also, yes they work in MySQL at least. My application uses them quite extensively, mainly to generate a dynamic date range. @aik099 Done |
Usage: $query->from(['foo' => $subquery])->join(['bar' => $subquery2], 'foo.id', '=', 'bar.id');
Taken from @jarredholman's work: 3ec55a1
A previous PR was created (#4238) but was closed due to implementation. The implementation in this PR is more correct.