I have two classes Contact and CompanyInfo that should exist in a 1:1
relation; CompanyInfo contains a comment related to Contact.  This works
-

class Contact(Base, KVC):
   ...
   _info = relation( 'CompanyInfo', 
                      uselist = False,
                      backref = backref( 'company_info_contact' ),
                      primaryjoin =
( 'CompanyInfo.parent_id==Contact.object_id' ) )

                    
    comment = association_proxy( '_info', 'text',  )

- so that the "text" value of the CompanyInfo object is presented as the
"comment" value of the Contact.  This is awesome!  [The database
is-the-way-it-is, other apps use it this way, I can't change it].

Only caveat is if you somehow [those darn other apps...] end up with a
Contact with no corresponding CompanyInfo object.   Then accessing
Contact.comment bombs out.

Is there anyway to get the SQLalchemy model to automatically create a
CompanyInfo object if one is missing?

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to