<commit_before>
var moment = require('moment');
var query = require('../utils/query'),
    sql = require('../utils/sql'),
    template = require('../utils/template');


exports.query = function (args) {
    var view = args.view,
        table = view.table,
        columns = view.columns;

    var names = [],
        joins = [],
        mtm = false;
    for (var i=0; i < columns.length; i++) {
        if (!columns[i].listview.show) continue;
        if (columns[i].oneToMany) {
            var ref = columns[i].oneToMany,
                cols = sql.fullNames(ref.table, ref.columns);
            names.push(sql.group(sql.cast(cols), columns[i].name));
            joins.push(sql.joins(table.name, columns[i].name, ref.table, ref.pk));
        }
        else if (columns[i].manyToMany) {
            mtm = true;
            var ref = columns[i].manyToMany.ref,
                cols = sql.fullNames(ref.table, ref.columns);

            names.push(sql.group(sql.cast(cols), columns[i].name));
            
            var link = columns[i].manyToMany.link;
            joins.push(sql.joins(table.name, table.pk, link.table, link.parentPk));
            joins.push(sql.joins(link.table, link.childPk, ref.table, ref.pk));
        }
        else {
            names.push(sql.fullName(table.name, columns[i].name));
        }
    }
    names.unshift(sql.pk(table.name, table.pk));

    // only when showing many to many columns!
    if (mtm) joins.push(sql.groupby(sql.fullName(table.name, table.pk)));

    var order = '';<commit_msg>Bugfix in listview for showing one to many values<commit_after>
var moment = require('moment');
var query = require('../utils/query'),
    sql = require('../utils/sql'),
    template = require('../utils/template');


exports.query = function (args) {
    var view = args.view,
        table = view.table,
        columns = view.columns;

    var names = [],
        joins = [];
    for (var i=0; i < columns.length; i++) {
        if (!columns[i].listview.show) continue;
        if (columns[i].oneToMany) {
            var ref = columns[i].oneToMany,
                cols = sql.fullNames(ref.table, ref.columns);
            names.push(sql.group(sql.cast(cols), columns[i].name));
            joins.push(sql.joins(table.name, columns[i].name, ref.table, ref.pk));
        }
        else if (columns[i].manyToMany) {
            var ref = columns[i].manyToMany.ref,
                cols = sql.fullNames(ref.table, ref.columns);

            names.push(sql.group(sql.cast(cols), columns[i].name));
            
            var link = columns[i].manyToMany.link;
            joins.push(sql.joins(table.name, table.pk, link.table, link.parentPk));
            joins.push(sql.joins(link.table, link.childPk, ref.table, ref.pk));
        }
        else {
            names.push(sql.fullName(table.name, columns[i].name));
        }
    }
    names.unshift(sql.pk(table.name, table.pk));

    // always group by pk inside the listview!
    joins.push(sql.groupby(sql.fullName(table.name, table.pk)));

    var order = '';
{'fraction_non_alphanumeric': 0.16141732283464566, 'fraction_numerical': 0.0006561679790026247, 'mean_word_length': 2.146542827657379, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3996564', 'n_tokens_mistral': 987, 'n_tokens_neox': 966, 'n_words': 184}