Skip to content

Conversation

RaitzeR
Copy link

@RaitzeR RaitzeR commented May 22, 2018

Checking exists changed to join, since it's insanely much faster (from tens or hundreds of seconds to milliseconds). Checking not exists is as before.

Through works with unlimited number of pivot tables.

Example:

'join2through' => array(
            'from_table'      => 'master2',
            'from_col'        => 'm2_col',
            'to_table'        => 'subtable2',
            'to_col'          => 's2_col',
            'to_value_column' => 's2_value',
            'not_exists'      => true,
            'through' => array(
            'from_table'      => 'subtable2',
            'from_col'        => 's2_col',
            'to_table'        => 'subtable3',
            'to_col'          => 's3_col',
            'to_value_column' => 's3_value',
            )
            ),

Keep adding "through" if there's more tables in between.

Checking exists changed to join, since it's insanely much faster (from tens or hundreds of seconds to milliseconds). Checking not exists is as before.

Through works with unlimited number of pivot tables.

Example:

'join2through' => array(
            'from_table'      => 'master2',
            'from_col'        => 'm2_col',
            'to_table'        => 'subtable2',
            'to_col'          => 's2_col',
            'to_value_column' => 's2_value',
            'not_exists'      => true,
            'through' => array(
            'from_table'      => 'subtable2',
            'from_col'        => 's2_col',
            'to_table'        => 'subtable3',
            'to_col'          => 's3_col',
            'to_value_column' => 's3_value',
            )
            ),

Keep adding "through" if there's more tables in between.
@RaitzeR
Copy link
Author

RaitzeR commented May 22, 2018

The failed tests comes from the fact that the tests check for exists, instead of how it's done now. I didn't want to rewrite the tests, in case you're not going to accept this pull request.

Copy link
Owner

@timgws timgws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, this is looking good. There are a few changes that I would prefer to be performed before accepting the changes.

Also, please ensure that the tests pass (of course!)

🎉 Thanks for your first contribution to this project!

$condition,
$not
);
if ( $not ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that I am cautious of is that this code looks like it will change the behavior for other users of this class.

Can we separate out the code inside the if() {...} block into two separate functions to ensure that the length of this function (buildSubclauseQuery) is not too long?

} else {
// Create a join clause to join to the other table, and find results matching the criteria

$query = $query->join( $subclause["to_table"], $subclause['to_table'] . '.' . $subclause['to_col'], '=', $subclause['from_table'] . '.' . $subclause['from_col'] );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to keep lines < 80 characters long. This line of code wraps in my browser.

$this->assertEquals(28, $bindings[1]->day);
}

public function testJoinNotExistsInThrough()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, with this project, we are trying to stick to PSR-2 styling (https://www.php-fig.org/psr/psr-2/). Could you please ensure that you are using spaces and not tabs to format code?

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.

2 participants