Just one more question regarding the inheritance config.
Is it possible to skip the add() part for parent?
Say there is already records in OauthUser and User, on the next run, only
insert new record into OauthUser and don't do anything on User table.
Thanks.
On Monday, October 28, 2013 2:06:59 PM UTC+11, Chung WONG 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?
>
> I have read the
> docs<http://docs.sqlalchemy.org/en/rel_0_9/orm/inheritance.html#joined-table-inheritance>
> about
> joined table inheritance, but it doesn't say anything about saving and I am
> not that familiar with inheritance config.
>
> Is it possible to save the data in one go, for example.
> DBsession.add(someuser) # it saves into two tables automatically
>
> or Do i have to do:
> DBsession.add(oauth_user_instance)
> DBsession.add(user_instance)
>
> Thanks.
>
>
>
>
--
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.