selfJoin method

Query selfJoin(
  1. dynamic tableName, {
  2. dynamic columnName,
  3. dynamic baseColumnName,
  4. Query function(
    1. Query q,
    2. String tableName,
    3. String baseTableName
    )?,
})

Implementation

Query selfJoin(tableName, {columnName, baseColumnName, Query Function(Query q, String tableName, String baseTableName)? function}) {
  if (function != null) {
    final rand = getRandomString(9);
    _joinQuery += ' INNER JOIN $tableName $rand ON ';
    Query q = function(Query(table: tableName), tableName, rand);
    q._self = false;
    q.table = table;
    _select += q._select;
    _joinQuery += q._joinQuery.replaceAll('{TABLE_COLUMN_FILL}', rand) + ' ' + q._lastQuery.replaceAll('WHERE', 'AND');
  } else {
    final rand = getRandomString(9);
    _joinQuery += ' INNER JOIN $tableName $rand ON ';
    _joinQuery += tableName + '.' + columnName;
    _joinQuery += '=';
    _joinQuery += rand + '.' + baseColumnName;
  }
  return this;
}