On Oct 27, 2013, at 11:06 PM, Chung WONG <[email protected]> wrote: > class User(Base): > from sqlalchemy.dialects.postgresql import INET > __tablename__ = 'users' > id = Column(Integer,Sequence('user_id_seq'), primary_key=True) > first_name = Column(Unicode(255),nullable=False) > last_name = Column(Unicode(255),nullable=False) > created_at = Column(DateTime,nullable=False,default=datetime.utcnow) > updated_at = Column(DateTime) > email = Column(String(255),nullable=False) > password= Column(String(60)) > > auth_providers=relationship("Oauth2User", backref="user") > > def __init__(self,**kw): > for key in kw: > self.__setattr__(key,kw[key]) > > > class Oauth2User(User): > __tablename__ = 'oauth2_user_info' > id = Column(Integer,Sequence('oauth2_user_id_seq'), primary_key=True) > user_id = Column(Integer, ForeignKey('users.id')) > uid = Column(Integer) > provider_id=Column(Unicode) > first_name = Column(Unicode(255),nullable=False) > last_name = Column(Unicode(255),nullable=False) > created_at = Column(DateTime,nullable=False,default=datetime.utcnow) > updated_at = Column(DateTime) > > There are two classes where Oauth2User inherits User, and both of them have > its own table. > If user info is returned by oauth provider and an instance of Oauth2User will > becreated, with all attributes setup probably. > How do I save that user into both tables users and oauth2_user_info?
you can see for yourself if you just take an Oauth2User as above, add() it to a Session, and watch the SQL with echo=True. Joined table inheritance is a fully implemented feature that considers the two tables for an Oauth2User object for all operations, persistence is included. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
