本文整理汇总了Python中orator.orm.builder.Builder.eager_load_relations方法的典型用法代码示例。如果您正苦于以下问题:Python Builder.eager_load_relations方法的具体用法?Python Builder.eager_load_relations怎么用?Python Builder.eager_load_relations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orator.orm.builder.Builder
的用法示例。
在下文中一共展示了Builder.eager_load_relations方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_eager_load_relations_load_top_level_relationships
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import eager_load_relations [as 别名]
def test_eager_load_relations_load_top_level_relationships(self):
flexmock(Builder)
builder = Builder(flexmock(QueryBuilder(None, None, None)))
nop1 = lambda: None
nop2 = lambda: None
builder.set_eager_loads({'foo': nop1, 'foo.bar': nop2})
builder.should_receive('_load_relation').with_args(['models'], 'foo', nop1).and_return(['foo'])
results = builder.eager_load_relations(['models'])
self.assertEqual(['foo'], results)
示例2: test_eager_load_accept_queries
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import eager_load_relations [as 别名]
def test_eager_load_accept_queries(self):
model = OrmBuilderTestModelCloseRelated()
flexmock(Builder)
builder = Builder(flexmock(QueryBuilder(None, None, None)))
nop1 = OrmBuilderTestModelFarRelatedStub.where('id', 5)
builder.set_eager_loads({'foo': nop1})
relation = flexmock()
relation.should_receive('add_eager_constraints').once().with_args(['models'])
relation.should_receive('init_relation').once().with_args(['models'], 'foo').and_return(['models'])
relation.should_receive('get_eager').once().and_return(['results'])
relation.should_receive('match').once()\
.with_args(['models'], ['results'], 'foo').and_return(['foo'])
builder.should_receive('get_relation').once().with_args('foo').and_return(relation)
relation.should_receive('merge_query').with_args(nop1).and_return(relation)
results = builder.eager_load_relations(['models'])
self.assertEqual(['foo'], results)
示例3: test_relationship_eager_load_process
# 需要导入模块: from orator.orm.builder import Builder [as 别名]
# 或者: from orator.orm.builder.Builder import eager_load_relations [as 别名]
def test_relationship_eager_load_process(self):
proof = flexmock()
flexmock(Builder)
builder = Builder(flexmock(QueryBuilder(None, None, None)))
def callback(q):
proof.foo = q
builder.set_eager_loads({'orders': callback})
relation = flexmock()
relation.should_receive('add_eager_constraints').once().with_args(['models'])
relation.should_receive('init_relation').once().with_args(['models'], 'orders').and_return(['models'])
relation.should_receive('get_eager').once().and_return(['results'])
relation.should_receive('get_query').once().and_return(relation)
relation.should_receive('match').once()\
.with_args(['models'], ['results'], 'orders').and_return(['models.matched'])
builder.should_receive('get_relation').once().with_args('orders').and_return(relation)
results = builder.eager_load_relations(['models'])
self.assertEqual(['models.matched'], results)
self.assertEqual(relation, proof.foo)