Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find selected column XXXX when use pagination and previously set a withColumn custom column for the select statement #1999

Open
c15k0 opened this issue Apr 10, 2024 · 0 comments

Comments

@c15k0
Copy link

c15k0 commented Apr 10, 2024

Taking this example:

$query = BookQuery:create()->withColumn('now()', 'exampleCurrentTs');
$results = $query->paginate(1, 50);

It throws an exception like:
throw new PropelException("Cannot find selected column '$columnName'"); in ModelCriteria.php at line 2389

What is the reason?, in order to create the count statement, in the Query classes there are some instructions that have to clear the selectColumns and asColumns arrays in order to add only the count(*) to the statement:

// Replace SELECT columns with COUNT(*)
$this->clearSelectColumns()->addSelectColumn('COUNT(*)');
$sql = $this->createSelectSql($params);

Everybody could find these three lines (including the comment) in the doCount method into every Query classes.

The problem is that the clearSelectColumns method from the Criteria class do this:

public function clearSelectColumns()
{
    $this->selectColumns = $this->asColumns = [];
    return $this;
}

instead of this:

public function clearSelectColumns()
{
    $this->selectColumns = $this->asColumns = $this->select = [];
    return $this;
}

And it causes the exception because the withColumn still being into the select when try to verify all the fields before doing the count.

I tried with several examples this change and it only affects to the count statements, so it could be a good fix for that.

Thanks

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

No branches or pull requests

1 participant