Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

A new way to count the number of rows #14

Closed
wants to merge 1 commit into from

Conversation

waldo2188
Copy link

Instead of to recreate a querybuilder for count the number of row, why not just clone the actual QueryBuilder?

In the case where we use this kind of code :

$datatable = $this->get('lankit_datatables')->getDatatable('WaldoMyBundle:Customer');

// Construction of DQL query
$datatable->makeSearch();

/* @var $queryBuilder \Doctrine\ORM\QueryBuilder */
$qb = $datatable->getQueryBuilder(); // we retrieve the QueryBuilder

// Here we add what we want in the query
// But I don't know why, it doesn't work really good if I use $qb->addSelect
$qb->select("Organisme.id, Organisme.sigle, Organisme.libelle, COUNT(ShoppingCart.id) as nbShoppingCart");
$qb->leftJoin("Customer.shoppingCart", "ShoppingCart")
->where(/* Lot of realy hard stuf */);

// We execute the query
$dataTableResult = $datatable->executeSearch();

// Add generate the response !
return $dataTableResult->getSearchResultsResponse();

When count of row is done the WHERE part isn't include. So we don't have the real number of row.

But if we just clone the QueryBuilder, it 's work fine (In my case).

Instead of to recreate a querybuilder for count the number of row, why not just clone the actual QueryBuilder?
@waldo2188
Copy link
Author

Please ignore this PR, she is buggy...

@waldo2188 waldo2188 closed this Apr 18, 2013
@ChadSikorra
Copy link
Member

Just to comment on this, I actually have made some pretty large changes to this bundle recently but I haven't pushed my changes yet. It should make doing things like getting the count of a column select more feasible rather than having to mess with the QueryBuilder instance like that. Anyway, I think you could add a WhereBuilderCallback (see the docs) which should stick and return the correct count.

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

Successfully merging this pull request may close these issues.

2 participants