I thought maybe there was a simpler way to do that, but the hybrid_property works. Thanks.
On Wed, Jul 8, 2015 at 11:19 AM, Mike Bayer <mike...@zzzcomputing.com> wrote: > > > 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 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. > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sqlalchemy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sqlalchemy/7azas9khOx0/unsubscribe. > To unsubscribe from this group and all its topics, 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. -- --- Pedro Werneck -- 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.