How to get only specific fields? #17
Answered
by
wallneradam
heindrickdumdum0217
asked this question in
Q&A
-
Is it possible to get only necessary fields? |
Beta Was this translation helpful? Give feedback.
Answered by
wallneradam
Aug 2, 2024
Replies: 1 comment 2 replies
-
It is indeed possible: async def test():
import esorm
class Model(esorm.ESModel):
f_int: int = 0
f_str: str = 'a'
await esorm.setup_mappings()
doc = Model(f_int=1, f_str='b')
doc_id = await doc.save()
assert doc_id is not None
doc = await Model.get(doc_id)
assert doc.f_str == 'b'
assert doc.f_int == 1
doc = await Model.search_one_by_fields(dict(_id=doc_id), _source=['f_str'])
assert doc.f_str == 'b'
assert doc.f_int == 0
doc = await Model.search_one_by_fields(dict(_id=doc_id), _source=['f_int'])
assert doc.f_str == 'a'
assert doc.f_int == 1 Though Esorm search methods accepts any parameters |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
wallneradam
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@heindrickdumdum0217
It is indeed possible:
Though
get
method has no_…