Jump to content

Duplication in Query Results


Jason Huck
 Share

Recommended Posts

Is there an easy way to get back the SQL query generated by a specific processwire selector? I have what appears to be a cartesian product and/or groupwise maximum bug in a selector, but I'm not sure how to confirm it.

I'm querying for a set of pages with a specific template which are related to the current page. The returned pages include a URL field and a file field. The selector looks like this:

$grades = $pages->find('template=grade,include=all,classification.title="'.$page->title.'",sort=series,sort=title');

"classification" is a page field. Series and title are text fields. I'm iterating through the results and outputting three text fields, a URL field, and a file (->url) field. On one of the nine pages using this query, it should only return one row, but it returns two. The text fields are identical for both rows. The URL and file fields are empty in the first row and populated in the second row. The other eight pages all work as expected with no duplication.

Thanks,
Jason
 

Link to comment
Share on other sites

Use getQueryLog() :-)

Maybe something like:

$queries = $database->getQueryLog();
foreach($queries as $query){
    if (strpos($query, 'classification')) {//just to limit our search since there could be other queries
        echo '<pre>' . $query . '</pre>';
    }
}
Edited by kongondo
Code example
  • Like 4
Link to comment
Share on other sites

you can call $database->getQueryLog():

     * Get an array of all queries that have been executed thus far
     *
     * Active in ProcessWire debug mode only
     *
     * @return array
     *

Edited by horst
Ah, again, Kongondo, - ;)
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...