Left join dose not return system fields

2 posts by 2 authors in: Forums > CMS Builder
Last Post: October 27, 2017   (RSS)

By Dave - October 27, 2017

Hi Brownleather, 

The undocumented "leftJoin" option for getRecords is a bit of an experiment/hack.  We use it ourselves from time to time, but I was never super happy with it.  I didn't find it much simpler than writing join queries.  In any case, if it's working for you there's no reason to stop using it and we can see about getting it to return the fields you need.

If this the code that's filtering out the fields:

// add fieldnames to SELECT
$foreignSchemaFields = getSchemaFields($foreignTable);
$validFieldTypes = array('textfield','textbox','wysiwyg','date','list','checkbox');
foreach (array_keys($foreignSchemaFields) as $fieldname) {
  if (in_array(@$foreignSchemaFields[$fieldname]['type'], $validFieldTypes) || @$fieldname == 'num') {
    $selectFields .= ",\n                           $foreignTable.`$fieldname` as `$foreignTable.$fieldname`";
  }

Then it's because the fields you mentioned have a type of 'none' that's not listed above.  Try this patch: 

// add fieldnames to SELECT
$foreignSchemaFields = getSchemaFields($foreignTable);
$validFieldTypes = ['textfield','textbox','wysiwyg','date','list','checkbox'];
$validFieldNames = ['num','createdDate','createdByUserNum','updatedDate','updatedByUserNum'];
foreach (array_keys($foreignSchemaFields) as $fieldname) {
  if (in_array(@$foreignSchemaFields[$fieldname]['type'], $validFieldTypes) || in_array($fieldname, $validFieldNames)) {
    $selectFields .= ",\n                           $foreignTable.`$fieldname` as `$foreignTable.$fieldname`";
  }

Let me know if that works for you or any other issues and I can add it to the next release.

Dave Edis - Senior Developer
interactivetools.com