MCPcopy Index your code
hub / github.com/tortoise/tortoise-orm / only

Method only

tortoise/queryset.py:956–978  ·  view source on GitHub ↗

Fetch ONLY the specified fields to create a partial model. Persisting changes on the model is allowed only when: * All the fields you want to update is specified in `` .save(update_fields=[...])`` * You included the Model primary key in the `.only(...)``

(self, *fields_for_select: str)

Source from the content-addressed store, hash-verified

954 return queryset # type: ignore
955
956 def only(self, *fields_for_select: str) -> QuerySet[MODEL]:
957 """
958 Fetch ONLY the specified fields to create a partial model.
959
960 Persisting changes on the model is allowed only when:
961
962 * All the fields you want to update is specified in ``<model>.save(update_fields=[...])``
963 * You included the Model primary key in the `.only(...)``
964
965 To protect against common mistakes we ensure that errors get raised:
966
967 * If you access a field that is not specified, you will get an ``AttributeError``.
968 * If you do a ``<model>.save()`` a ``IncompleteInstanceError`` will be raised as the model is, as requested, incomplete.
969 * If you do a ``<model>.save(update_fields=[...])`` and you didn&#x27;t include the primary key in the ``.only(...)``,
970 then ``IncompleteInstanceError`` will be raised indicating that updates can&#x27;t be done without the primary key being known.
971 * If you do a ``<model>.save(update_fields=[...])`` and one of the fields in ``update_fields`` was not in the ``.only(...)``,
972 then ``IncompleteInstanceError`` as that field is not available to be updated.
973 """
974 if not fields_for_select:
975 raise ValueError(".only() requires at least one field")
976 queryset = self._clone()
977 queryset._fields_for_select = fields_for_select
978 return queryset
979
980 def select_related(self, *fields: str) -> QuerySet[MODEL]:
981 """

Calls 1

_cloneMethod · 0.95