joins method

  1. @override
QueryMethod<T?> joins(
  1. List<Type> args
)
override

joins method

Implementation

@override
QueryMethod<T?> joins(List<Type> args) {
  _joins
    ..clear()
    ..addAll(
      args.map((arg) {
        final dao = QuickeyDB.getInstance!.dataAccessObjects![arg]!;

        /// get [include] ForeignKey
        final foreignKey = schema.foreignKeys.find(
          (foreignKey) => foreignKey.reference!.table == dao.schema.table,
        )!;

        /// Add inner join
        _select.add('INNER JOIN ${dao.schema.table} ON ${dao.schema.table}.'
            '${dao.schema.primaryKey} = ${schema.table}.${foreignKey.parent}');

        /// Add inner join columns
        _columns.addAll(
          dao.schema.columns.map((column) {
            /// table.column AS type_column
            return '${dao.schema.table}.${column.name} AS '
                '${dao.type.toString().toCamelCase()}_${column.name}';
          }).toList(),
        );

        return dao;
      }),
    );

  return this;
}