On 7/8/15 12:15 AM, Pedro Werneck wrote:
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?
why not make a @hybrid_property called "active", call the relationship
_active, and then customize access completely?
--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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/d/optout.