Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

mergeWith does not merge select queries #391

Open
Ventzy opened this Issue Jun 22, 2012 · 2 comments

Comments

Projects
None yet
2 participants

Ventzy commented Jun 22, 2012

$criteria->mergeWith($otherCriteria);

If $otherCriteria has added select queries like this $otherCriteria->addSelectQuery($query, 'alias'); it is not merged to $criteria.
One solution in mergeWith method could be this:

$selectCriterias = $criteria->getSelectQueries();
foreach ($selectCriterias as $alias => $selectCriteria) {
$this->addSelectQuery($selectCriteria, $alias);
}

However this is not full solution, because of the third parameter in ModelCriteria::addSelectQuery.
If the original call is $otherCriteria->addSelectQuery($query, 'alias', false), as it is in my use case, the above solution won't work. Unfortunatelly, the value of the third parameter - $addAliasAndSelectColumns is not stored in the model criteria, so it can't be restored for the call in the mergeWith method.

Owner

willdurand commented Jun 22, 2012

The third parameter modifies the current criteria (https://github.com/propelorm/Propel/blob/master/runtime/lib/query/ModelCriteria.php#L1024), so do you really need this parameter in the mergeWith() method (assuming we add the few lines you provided)?

Ventzy commented Jun 23, 2012

Yes, its needed. Initially, in my workaround of the problem I merged my criterias without considering the third parameter, but this caused problems. I use "false" for the third parameter and if it is not used in merge code it leads to $this->addSelfSelectColumns() call in addSelectQuery(), which changes intended select columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment