Map only certain parts of the class to a database using SQLAlchemy?

Posted by Az on Stack Overflow See other posts from Stack Overflow or by Az
Published on 2010-03-25T20:54:22Z Indexed on 2010/03/26 0:33 UTC
Read the original article Hit count: 359

Filed under:
|
|
|

When mapping an object using SQLAlchemy, is there a way to only map certain elements of a class to a database, or does it have to be a 1:1 mapping?

Example:

class User(object):
    def __init__(self, name, username, password, year_of_birth):
        self.name = name
        self.username = username
        self.password = password
        self.year_of_birth = year_of_birth

Say, for whatever reason, I only wish to map the name, username and password to the database and leave out the year_of_birth. Is that possible and will this create problems?

Edit - 25/03/2010

Additionally, say I want to map username and year_of_birth to a separate database. Will this database and the one above still be connected (via username)?

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy