1. Ben Trofatter
  2. sqlalchemy-2663


Mike Bayer  committed fe455fa


  • Participants
  • Parent commits 8c9177a
  • Branches default

Comments (0)

Files changed (1)

File doc/build/content/mappers.txt

View file
 However, the approach above is not complete.  While our `EmailAddress` object will shuttle the value through the `email` descriptor and into the `_email` mapped attribute, the class level `EmailAddress.email` attribute does not have the usual expression semantics usable with `Query`.  To provide these, we instead use the `synonym()` function as follows:
-    mapper(MyAddress, addresses_table, properties={
+    mapper(EmailAddress, addresses_table, properties={
         'email': synonym('_email', map_column=True)
 The `email` attribute is now usable in the same way as any other mapped attribute, including filter expressions, get/set operations, etc.:
-    address = sess.query(MyAddress).filter(MyAddress.email == 'some address').one()
+    address = sess.query(EmailAddress).filter(EmailAddress.email == 'some address').one()
     address.email = 'some other address'
-    q = sess.query(MyAddress).filter_by(email='some other address')
+    q = sess.query(EmailAddress).filter_by(email='some other address')
 If the mapped class does not provide a property, the `synonym()` construct will create a default getter/setter object automatically.