zendframework / zend-db

Db component from Zend Framework
BSD 3-Clause "New" or "Revised" License
101 stars 122 forks source link

SQL Abstraction, Select API #176

Open dafap opened 7 years ago

dafap commented 7 years ago

In the Select section, API description, replace

public function join(string|array $name, string $on, string|array $columns = self::SQL_STAR, string $type = self::JOIN_INNER) : self;

by

public function join(string|array $name, string|Zend\Db\Sql\ExpressionInterface $on, string|array $columns = self::SQL_STAR, string $type = self::JOIN_INNER) : self;
ezimuel commented 7 years ago

@dafap I see $on is string in the source code. Can you give an example of $on accepting Zend\Db\Sql\ExpressionInterface? Thanks.

dafap commented 7 years ago

This is possible using the ON clause as a ExpressionInterface :

$on = new Literal('browser_stats_daily.user_agent LIKE user_agents.user_agent');
$select = $this->tableGateway->getSql()->select();
$select->quantifier(Select::QUANTIFIER_DISTINCT)
       ->columns(["user_agent"])
       ->join("browser_stats_daily", $on, Select::SQL_STAR, Select::JOIN_RIGHT)
       ->where->isNotNull("user_agents.user_agent");
michalbundyra commented 4 years ago

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at https://github.com/laminas/laminas-db/issues/93.