We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28840
    • 46 Posts
    How can I set equivalent of MYSQL "SELECT `table_name`.`field_name` AS `alias_name`" with xPDO on GetSelectColumns? There isn't any examples for that. Is that even possible or do I have to use direct SQL in SELECT statment?

    Sumoborac
      • 28840
      • 46 Posts
      OK, after "grep"ing thru the core folder for any clues the getnodes.processor.php gave me a hint.

      $c->select(array(
      $modx->getSelectColumns('objectName','objectName','',array('field_name')).' AS `alias_name`'
      ));


      This works, but is there any smoother way to do this inside the getSelectColumns function? Probably from inside array() but I have no idea how smiley

      Sumoborac
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: sumoborac at Nov 03, 2013, 12:55 PM
        OK, after "grep"ing thru the core folder for any clues the getnodes.processor.php gave me a hint.

        $c->select(array(
        $modx->getSelectColumns('objectName','objectName','',array('field_name')).' AS `alias_name`'
        ));


        This works, but is there any smoother way to do this inside the getSelectColumns function? Probably from inside array() but I have no idea how smiley

        Sumoborac

        An alternate approach without getSelectColumns()...

        $c->select(
            array(
                'alias_name' => "{$modx->escape('objectAlias')}.{$modx->escape('field_name')}"
            )
        );


        What do you mean by smoother way?
          • 28840
          • 46 Posts
          Quote from: opengeek at Nov 04, 2013, 01:49 PM

          An alternate approach without getSelectColumns()...

          $c->select(
              array(
                  'alias_name' => "{$modx->escape('objectAlias')}.{$modx->escape('field_name')}"
              )
          );


          What do you mean by smoother way?

          Something like:
          $c->getSelectColumns('objectName','objectAlias','',array('fieldName:AS'=>'fieldAlias'));


          But your solution is also an option smiley

          Sumoborac