We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19534
    • 183 Posts
    Hi,

    to find solutions for my problems http://modxcms.com/forums/index.php/topic,61184.0.html and http://modxcms.com/forums/index.php/topic,61189.0.html
    I’d like to see what SQL xPDO sends to the database server. I found the xPDOCriteria.toSQL()method which looks promising for this purpose.

    I tried
    <?php
    $obecjtGraph = '{ "Products":{ "Prices":{} } }';
    $criteria = $modx->newQuery('nittelCategory');
    $criteria->bindGraph($obecjtGraph);
    echo '['.$criteria->toSQL().']';
    

    But this returns only [].

    Even after performing the query [] is returned:
    <?php
    $obecjtGraph = '{ "Products":{ "Prices":{} } }';
    $criteria = $modx->newQuery('Category');
    $criteria->bindGraph($obecjtGraph);
    $categories = $modx->getCollectionGraph('Category', $obecjtGraph, $criteria);
    echo '['.$criteria->toSQL().']';
    


    Am I doing something wrong?

    Thanks!
      Add-On to easily manage your multilingual sites: Babel
      • 28215
      • 4,149 Posts
      When calling queries with getObjectGraph/getCollectionGraph, before using toSql(), you need to call:

      $criteria->prepare();
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 13481
        • 97 Posts
        Another way to do it is to just turn on debugging and call die() right after your statement. I find it useful to see everything that is going on before my query happens. It’s like a huge stack trace. To turn on debugging call

        $this->setDebug(true);


        If found that to get this to work I had to put it in my constructor.

        Once you have your debug output on the screen and easy way to find errors is to just search for the string "error" using your browser’s find feature.

        James
          • 19534
          • 183 Posts
          Thanks a lot!
            Add-On to easily manage your multilingual sites: Babel