We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14372
    • 49 Posts
    I was able to do it with this ...


      $query = $modx->newQuery('modUserProfile');
    
      $query->innerJoin('modUserGroupMember', 'UG', array("modUserProfile.internalKey = UG.member"));
    
      $ah_user_collection = $modx->getCollection('modUserProfile',$query);


    I joined the two table so when for example I specify a filter using the WHERE call

      $query->where(array(
        'UG.user_group' => '3',
      ));


    It gave me only the user’s who fit that criteria.

    :-)
      • 42215
      • 17 Posts
      I am trying to get a list of name-value pairs of all TVs of a Resource, in a Snippet. And I am having the problem of innerJoin + select (with both string argument and the commented $modx->getSelectColumns statements) not working together. The code is:
      $criteria = $modx->newQuery('modTemplateVar');
      
      $criteria->innerJoin(
      	'modTemplateVarResource', 
      	'TVi', 
      	array('`modTemplateVar`.id = TVi.tmplvarid')
      );
      
      $criteria->select('`modTemplateVar`.`caption`, `TVi`.`value`');
      /* $criteria->select($modx->getSelectColumns(
      	'modTemplateVar', 
      	'modTemplateVar', 
      	'',
      	array('caption')
      ));
      $criteria->select($modx->getSelectColumns(
      	'modTemplateVarResource',
      	'TVi',
      	'',
      	array('value')
      )); */
      
      $criteria->where(
      	array('TVi.contentid'=>$modx->resource->get('id'),
      	'TVi.value:!=' => '')
      );
      // $criteria->prepare();
      // return $criteria->toSQL();
      
      $tvs = $modx->getCollection('modTemplateVar',$criteria);
      It gives
      Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in /my/site/path/core/xpdo/om/xpdoobject.class.php on line 116
      Uncommenting return prints the query:
      SELECT `modTemplateVar`.`caption`, `TVi`.`value` 
      FROM `bsaz_site_tmplvars` AS `modTemplateVar` 
      JOIN `bsaz_site_tmplvar_contentvalues` `TVi` 
      ON `modTemplateVar`.id = TVi.tmplvarid 
      WHERE ( `TVi`.`contentid` = '12' AND `TVi`.`value` != '' )


      As jaredloman mentioned, removing the select makes the code work, but I really need that value column in the result.

      Could anyone please point at where I am doing wrong, or suggest some other solution?

      Thanks!
        • 3749
        • 24,544 Posts
        This could be the problem (from rtfm):

        When selecting fields, always make sure to at least include the Primary Key of the table; otherwise, xPDO will not be able to make an object from it and get lost in recursion with the error that the maximum number of nested functions of 100 has been exceeded.

        http://rtfm.modx.com/xpdo/2.x/class-reference/xpdoquery/xpdoquery.select

        array('id','value')


        Unless you're getting a huge result set, you could just leave out the select. There are only two columns of a TVR that you're not getting, and they're both integers. [ed. note: BobRay last edited this post 12 years, 8 months ago.]
          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
          • 42215
          • 17 Posts
          @BobRay That really was it. Added id columns from both tables, and it worked. Thank you!
            • 3749
            • 24,544 Posts
            Glad you got it sorted. wink
              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