'Trim joins from the start of the join path. The candidates for trim
are the PathInfos in names_with_path structure that are m2m joins.
Also set the select column so the start matches the join.
This method is meant to be used for generating the subquery joins &
cols in split_exclude().
Return a lookup usable for doing outerq.filter(lookup=self) and a
boolean indicating if the joins in the prefix contain a LEFT OUTER join.'

def trim_start(self, names_with_path):

    all_paths = []
    for (_, paths) in names_with_path:
        all_paths.extend(paths)
    contains_louter = False
    lookup_tables = [t for t in self.alias_map if ((t in self._lookup_joins) or (t == self.base_table))]
    for (trimmed_paths, path) in enumerate(all_paths):
        if path.m2m:
            break
        if (self.alias_map[lookup_tables[(trimmed_paths + 1)]].join_type == LOUTER):
            contains_louter = True
        alias = lookup_tables[trimmed_paths]
        self.unref_alias(alias)
    join_field = path.join_field.field
    paths_in_prefix = trimmed_paths
    trimmed_prefix = []
    for (name, path) in names_with_path:
        if ((paths_in_prefix - len(path)) < 0):
            break
        trimmed_prefix.append(name)
        paths_in_prefix -= len(path)
    trimmed_prefix.append(join_field.foreign_related_fields[0].name)
    trimmed_prefix = LOOKUP_SEP.join(trimmed_prefix)
    if (self.alias_map[lookup_tables[(trimmed_paths + 1)]].join_type != LOUTER):
        select_fields = [r[0] for r in join_field.related_fields]
        select_alias = lookup_tables[(trimmed_paths + 1)]
        self.unref_alias(lookup_tables[trimmed_paths])
        extra_restriction = join_field.get_extra_restriction(self.where_class, None, lookup_tables[(trimmed_paths + 1)])
        if extra_restriction:
            self.where.add(extra_restriction, AND)
    else:
        select_fields = [r[1] for r in join_field.related_fields]
        select_alias = lookup_tables[trimmed_paths]
    for table in self.alias_map:
        if (self.alias_refcount[table] > 0):
            self.alias_map[table] = BaseTable(self.alias_map[table].table_name, table)
            break
    self.set_select([f.get_col(select_alias) for f in select_fields])
    return (trimmed_prefix, contains_louter)
