We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23134
    • 33 Posts
    How make that query on xpdo:
        select * from modx_site_content as SC
        left join
        (
        select thread, max(createdon) as d_max from modx_quip_comments as QC
        group by thread
        ) as T
        ON CONCAT('topic', SC.id) = T.thread
        where SC.parent IN (13, 17, 23, 45)
        ORDER BY d_max DESC
        LIMIT 0, 10
    


    it is real? Thanks!!!
      • 3749
      • 24,544 Posts
      See this: http://rtfm.modx.com/display/xPDO20/xPDOQuery


      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 34012
        • 88 Posts
          Almost retired from web-development industry but still randomly writing at Lazylegs.info and on schedule hopefully in near future to finish Oracle and PostgreSQL ports of MODX
          • 23134
          • 33 Posts
          Thank you very much for the links, but you can show xpdo code for my example?
            • 3749
            • 24,544 Posts
            It's too complex for me to do off the top of my head, but maybe someone else will chime in.

            What have you tried based on the docs in the link I posted?


            ---------------------------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
            MODX info for everyone: http://bobsguides.com/modx.html
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 23134
              • 33 Posts
              Quote from: BobRay at Mar 07, 2012, 02:51 PM

              What have you tried based on the docs in the link I posted?

              I do not know in what sequence to use methods xpdo in this problem ...
                • 3749
                • 24,544 Posts
                It doesn't matter. Setting the joins, sort criteria, order, limit, etc. can be done in any order as long as they come before the getCollection() call.



                ---------------------------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                MODX info for everyone: http://bobsguides.com/modx.html
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 34012
                  • 88 Posts
                  Unfortunately xPDO does not support join like that right now, the join methods require class to be set so had to do another way around the issue. Lucky that I got one site with quip and could duplicate it in to your form to support the CONCAT();

                  Instead of doing a left join, you can use subquery at ORDER BY 'sortby()' as shown below:

                  $quip = $modx->getService('quip','Quip',$modx->getOption('quip.core_path',null,$modx->getOption('core_path').'components/quip/').'model/quip/',$scriptProperties);
                  $cTable= $modx->getTableName("quipComment");
                  $c = $modx->newQuery('modResource');
                  $c->where(array("parent:IN" => array(13, 17, 23, 45)));
                  $c->sortby("(SELECT max(createdon) FROM {$cTable} WHERE thread = CONCAT('topic', modResource.id))", 'DESC');
                  $c->limit(10, 0);


                  This is tested to work, had different parents but the method is solid.

                  The SQL query for this is:

                  SELECT `modResource`.`id` AS `modResource_id`, `modResource`.`type`... FROM `modx_site_content` AS `modResource` WHERE `modResource`.`parent` IN (2,33) ORDER BY (SELECT max(createdon) FROM `modx_quip_comments` WHERE thread = CONCAT('topic', modResource.id)) DESC LIMIT 10


                  Truncated the select part a bit as there are few columns selected. The order of methods does not matter like Bob said, but personally want to keep them in SQL order so it makes it easier to read ad modify later on.

                  Note, you need to call the Quip service or add it as a package to snippet to be able to use the schema. [ed. note: lazylegs last edited this post 14 years, 7 months ago.]
                    Almost retired from web-development industry but still randomly writing at Lazylegs.info and on schedule hopefully in near future to finish Oracle and PostgreSQL ports of MODX