diff --git a/angel_orm/lib/src/query.dart b/angel_orm/lib/src/query.dart index 98f93a85..65f38bc8 100644 --- a/angel_orm/lib/src/query.dart +++ b/angel_orm/lib/src/query.dart @@ -13,9 +13,15 @@ abstract class Query extends QueryBase { final Map _names = {}; final List _orderBy = []; + // An optional "parent query". If provided, [reserveName] will operate in + // the parent's context. + final Query parent; + String _crossJoin, _groupBy; int _limit, _offset; + Query({this.parent}); + /// A reference to an abstract query builder. /// /// This is usually a generated class. @@ -32,6 +38,7 @@ abstract class Query extends QueryBase { /// Returns a unique version of [name], which will not produce a collision within /// the context of this [query]. String reserveName(String name) { + if (parent != null) return parent.reserveName(name); var n = _names[name] ??= 0; _names[name]++; return n == 0 ? name : '${name}$n';