python - Django ORM's "related data" loading behavior -
In LINQ (I came from C # background), you can manually load the data ("xxx" by including the data for the inserted table)
to ctx.MainTable.Include (" subtabile ");
In the above code, each instance of the menu item is loaded and all the subtable data are also loaded. If "Include" is not called, then the subtebable property of each metabyll will return.
What are the same methods for Django ORM? If not, then what is the default designated behavior for seats as above?
Check it out:
You Follow Relationships To do a select_related
query set and pre-fetch related rows.
Normally, you do not waste too much time unless you know that the personal projection made by ORM is very slow.
When you simply name the related object field:
x = MainTable.objects.get (id = "some object") y = x.subTable
The related subtab line will be ORM what's going to be lazy.
You can not get a table entirely in memory QuerySets are "lazy" and do not receive rows, unless there is no possible excuse. Consider this. For MainTable.objects.all () in the
y: y = m.subTable if y.someAttribute & gt; 5: Break
Then you can not actually need all the items in the main telephony
query set is ready to bring them. It really does not really bring them all, this is the reason that we generally do nothing more than x.subTable
and leave the ORM to fetch the line according to the need .
Once you can prove that it is very slow. After this you can MainTable.objects.select_related () ...
and force the rows to navigate in other tables.
Comments
Post a Comment