Let's say I have a table 'user', and for backwards compatibility reasons I 
have a single-column table named 'user_active' which is basically just a 
foreign key used as a boolean flag. I need my User model to have the 
'active' field as a boolean mapped to that one-to-one relationship. So, I 
have something like this:


class User(db.Model):
    __tablename__ = 'user'
    user_id = db.Column(db.Integer, primary_key=True)
    # ... other fields

    active = relationship('UserActive', backref='user', uselist=False)


class UserActive(db.Model)
    __tablename__ = 'user_active'
    user_id = db.Column(db.Integer, db.ForeignKey('user.user_id')


Using the simple relationship like that returns either the UserActive 
instance, or None, which isn't ideal as True or False but works fine in any 
boolean context. My problem is assignment and querying. How can can I get 
it to work in a way that setting User.active = True creates the new 
UserActive instance, and querying for User.active == True works as a join, 
not a subquery?

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to