Creating entity instances
Now, let’s create five objects that describe three persons and two cars, and save this information in the database:
>>> p1 = Person(name='John', age=20)
>>> p2 = Person(name='Mary', age=22)
>>> p3 = Person(name='Bob', age=30)
>>> c1 = Car(make='Toyota', model='Prius', owner=p2)
>>> c2 = Car(make='Ford', model='Explorer', owner=p3)
>>> commit()
Pony does not save objects in the database immediately. These objects will be saved only after the commit()
function is called. If the debug mode is turned on, then during the commit()
, you will see five INSERT
commands sent to the database.