26

Nested Model in Google Firestore - FireO

 4 years ago
source link: https://www.tuicool.com/articles/2AZ3QrV
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Nested Model

Table of contents

Model inside another model.

Example Usage

class User(Model):
    name = TextField()


class Student(Model):
    address = TextField()
    user = NestedModel(User)


u = User(name='Nested_Model')

s = Student(address="Student_address")
s.user = u
s.save()

Common mistake

Don’t save the NestedModel otherwise this model will save separately and can not be used in other model.

Invalid:Don’t save the NestedModel

u = User(name='Nested_Model')
u.save()  # Don't save nested model

s = Student(address="Student_address")
s.user = u
s.save()

Allowed Attributes

The following attributes supported by Nested Model.

  • Default

    Default value for field. This is base attribute that is available in all fields.Read More

  • Required

    Set True if value is required for the field. This is base attribute that is available in all fields.Read More

  • Column Name

    Set different column name in Firestore instead of field name. This is base attribute that is available in all fields.Read More

  • Validator

    Validate given value of field. This is base attribute that is available in all fieldsRead More


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK