zend-db
zend-db copied to clipboard
join colums not reset
https://github.com/zendframework/zend-db/blob/748f065ab8e64ab66213182a671513e9499957bc/src/Sql/Select.php#L426
case self::COLUMNS:
$this->columns = array();
foreach ($this->joins as &$join){
$join['columns'] = [];
}
break;
@hemengze
The entire joins property is reset:
https://github.com/zendframework/zend-db/blob/748f065ab8e64ab66213182a671513e9499957bc/src/Sql/Select.php#L428-L430
when work with paginator, sql like this:
select count(*), b.id, b.created_at from A as a inner join B as b on A.bid = b.id limit 1;
@hemengze
when work with paginator, sql like this:
Sorry, I don't understand. Please describe your problem with full sentence. This will help. Thanks!
Maybe you mean this cloning:
https://github.com/zendframework/zend-paginator/blob/master/src/Adapter/DbSelect.php#L142-L145
@froschdesign thank you. When I'm join a table with columns, reset the columns, the join columns still exists
$select = (new (Select))->join('B b', 'a.bid = b.id', 'id, created_at');
$select->reset(Select::COLUMNS);
$select->reset(Select::LIMIT);
$select->reset(Select::OFFSET);
$select->reset(Select::ORDER);
the columns b.id, b.created_at already exists
can something like this solve this problem?
public static function getCountSelect(Select $originalSelect, $fieldCountCriteria="id" )
{
$select = clone $originalSelect;
$select->reset(Select::COLUMNS);
$select->reset(Select::LIMIT);
$select->reset(Select::OFFSET);
$select->reset(Select::ORDER);
$select->reset(Select::GROUP);
/** @var Join $joins */
$joins = $select->joins->getJoins();
$select->reset(Select::JOINS);
foreach ($joins as $key => $join) {
//re add join without cols
$type = $join["type"];
$select->join($join["name"], $join["on"], [], $type);
}
$select->columns(["total" => new Expression("count(distinct($fieldCountCriteria))")]);
return $select;
}
It will re-init the joins without any column set. It seems working for my situation... try at your own risk :smiley:
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/60.