Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Expression throws Runtime Exception when named parameter used twice #111

Closed
manchuck opened this issue Apr 28, 2016 · 1 comment
Closed

Comments

@manchuck
Copy link

Trying to create:

SELECT
  uf.friend_id AS friend_id, 
  u.*
FROM users AS u
   LEFT JOIN user_friends AS uf ON uf.user_id = :user_id OR uf.friend_id = :user_id

When trying to use the same parameter twice like so:

$select = new Select(['u' => 'users']);
$select->join(
    ['uf' => 'user_friends'],
    new Expression(
        'uf.user_id = :user_id OR uf.friend_id = :user_id',
        ['user_id' => $userId]
    ),
    ['friend_id' => 'friend_id'],
    Select::JOIN_LEFT
);

$sql = new \Zend\Db\Sql\Sql($this->pivotTable->getAdapter());
$stmt = $sql->prepareStatementForSqlObject($select);

Expression will throw a Runtime Exception: The number of replacements in the expression does not match the number of parameters

The following workaround works just fine:

$select = new Select(['u' => 'users']);
$select->join(
    ['uf' => 'user_friends'],
    new Expression(
        'uf.user_id = ? OR uf.friend_id = ?',
        [$userId, $userId]
    ),
    ['friend_id' => 'friend_id'],
    Select::JOIN_LEFT
);

$sql = new \Zend\Db\Sql\Sql($this->pivotTable->getAdapter());
$stmt = $sql->prepareStatementForSqlObject($select);
@samsonasik
Copy link
Contributor

refs PR #112

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants