add fields method limiting the models columns fetched from db
This commit is contained in:
@ -29,7 +29,7 @@ class Track(ormar.Model):
|
||||
album = await Album.objects.create(name="Brooklyn")
|
||||
await Track.objects.create(album=album, title="The Bird", position=1)
|
||||
|
||||
# explicit preload of related Album Model
|
||||
# explicit preload of columns Album Model
|
||||
track = await Track.objects.select_related("album").get(title="The Bird")
|
||||
assert track.album.name == 'Brooklyn'
|
||||
# Will produce: True
|
||||
|
||||
@ -33,7 +33,7 @@ print('name' in course.__dict__)
|
||||
print(course.name)
|
||||
# Math <- value returned from underlying pydantic model
|
||||
print('department' in course.__dict__)
|
||||
# False <- related model is not stored on Course instance
|
||||
# False <- columns model is not stored on Course instance
|
||||
print(course.department)
|
||||
# Department(id=None, name='Science') <- Department model
|
||||
# returned from AliasManager
|
||||
|
||||
Reference in New Issue
Block a user