getFieldsAs method

List<QSelectField> getFieldsAs([
  1. String from = '',
  2. String newAlias = ''
])

Generates a list of QSelectField objects for SELECT queries with aliases.

from is the source table/alias prefix for field names as is the target alias prefix for the result fields

Returns a list of QSelectField objects that can be used in SELECT statements.

Example:

final fields = table.getFieldsAs('u', 'user');
// Generates: u.id AS user.id, u.name AS user.name, etc.

Implementation

List<QSelectField> getFieldsAs([String from = '', String newAlias = '']) {
  return fields.map((field) {
    return QSelect(
      from.isEmpty ? field.name : '$from.${field.name}',
      as: newAlias.isEmpty ? '' : '${newAlias}_${field.name}',
    );
  }).toList();
}