MCPcopy Index your code
hub / github.com/ormar-orm/ormar / load_data

Method load_data

ormar/queryset/queries/prefetch_query.py:203–246  ·  view source on GitHub ↗

Ensures that at least primary key columns from current model are included in the query. Gets the filter values from the parent model and runs the query. Triggers a data load in child tasks.

(self)

Source from the content-addressed store, hash-verified

201 self.source_model = source_model
202
203 async def load_data(self) -> None:
204 """
205 Ensures that at least primary key columns from current model are included in
206 the query.
207
208 Gets the filter values from the parent model and runs the query.
209
210 Triggers a data load in child tasks.
211 """
212 self._update_excludable_with_related_pks()
213 if self.relation_field.is_multi:
214 query_target = self.relation_field.through
215 select_related = [self.target_name]
216 else:
217 query_target = self.relation_field.to
218 select_related = []
219
220 filter_clauses = self.get_filter_for_prefetch()
221
222 if filter_clauses:
223 qry = Query(
224 model_cls=query_target,
225 select_related=select_related,
226 filter_clauses=filter_clauses,
227 exclude_clauses=[],
228 offset=None,
229 limit_count=None,
230 excludable=self.excludable,
231 order_bys=self._extract_own_order_bys(),
232 limit_raw_sql=False,
233 )
234 expr = qry.build_select_expression()
235 logger.debug(
236 expr.compile(
237 dialect=self.source_model.ormar_config.database.dialect,
238 compile_kwargs={"literal_binds": True},
239 )
240 )
241
242 async with query_target.ormar_config.database.get_query_executor() as exctr:
243 self.rows = await exctr.fetch_all(expr)
244
245 for child in self.children:
246 await child.load_data()
247
248 def _update_excludable_with_related_pks(self) -> None:
249 """

Callers

nothing calls this directly

Calls 8

QueryClass · 0.90
get_query_executorMethod · 0.80
fetch_allMethod · 0.80
load_dataMethod · 0.45

Tested by

no test coverage detected