Skip to content

Commit

Permalink
Merge pull request #638 from Lynesth/patch-12
Browse files Browse the repository at this point in the history
Code refactoring to bail out of parseJoin faster
  • Loading branch information
gabordemooij committed Apr 27, 2018
2 parents d45c49f + 37eaf64 commit 3b52e0c
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions RedBeanPHP/OODBBean.php
Expand Up @@ -324,24 +324,27 @@ public static function setMetaAll( $beans, $property, $value )
*/
private function parseJoin( $type )
{
if ( strpos($this->withSql, '@joined.' ) === FALSE ) {
return '';
}

$joinSql = '';
$joins = array();
if ( strpos($this->withSql, '@joined.' ) !== FALSE ) {
$writer = $this->beanHelper->getToolBox()->getWriter();
$oldParts = $parts = explode( '@joined.', $this->withSql );
array_shift( $parts );
foreach($parts as $part) {
$explosion = explode( '.', $part );
$joinInfo = reset( $explosion );
//Dont join more than once..
if ( !isset( $joins[$joinInfo] ) ) {
$joins[ $joinInfo ] = TRUE;
$joinSql .= $writer->writeJoin( $type, $joinInfo, 'LEFT' );
}
$writer = $this->beanHelper->getToolBox()->getWriter();
$oldParts = $parts = explode( '@joined.', $this->withSql );
array_shift( $parts );
foreach($parts as $part) {
$explosion = explode( '.', $part );
$joinInfo = reset( $explosion );
//Dont join more than once..
if ( !isset( $joins[$joinInfo] ) ) {
$joins[ $joinInfo ] = TRUE;
$joinSql .= $writer->writeJoin( $type, $joinInfo, 'LEFT' );
}
$this->withSql = implode( '', $oldParts );
$joinSql .= ' WHERE ';
}
$this->withSql = implode( '', $oldParts );
$joinSql .= ' WHERE ';

return $joinSql;
}

Expand Down

0 comments on commit 3b52e0c

Please sign in to comment.