@@ -260,7 +260,10 @@ def relationship(source, relationship, where, order_by):
260260 pagination parameters.
261261
262262 Args:
263- source (DbObject): A database object whose related objects are sought.
263+ source (DbObject or type): If a `DbObject` then the source of the
264+ relationship (the query originates from that particular object).
265+ If `type`, then the source of the relationship is implicit, even
266+ without the ID. Used for expanding from Organization.
264267 relationship (Relationship): The relationship.
265268 where (Comparison, LogicalExpression or None): The `where` clause
266269 for filtering.
@@ -274,11 +277,11 @@ def relationship(source, relationship, where, order_by):
274277 to_many = relationship .relationship_type == Relationship .Type .ToMany
275278 subquery = Query (relationship .graphql_name , relationship .destination_type ,
276279 where , to_many , order_by )
277- source_type_name = type (source ).type_name ()
278- query = Query ( utils . camel_case ( source_type_name ), subquery ,
279- type ( source ). uid == source . uid )
280+ query_where = type (source ).uid == source . uid if isinstance ( source , Entity ) \
281+ else None
282+ query = Query ( utils . camel_case ( source . type_name ()), subquery , query_where )
280283 return query .format_top (
281- "Get" + source_type_name + utils .title_case (relationship .graphql_name ))
284+ "Get" + source . type_name () + utils .title_case (relationship .graphql_name ))
282285
283286
284287def create (entity , data ):
0 commit comments