On Aug 22, 2012, at 3:51 PM, David McKeone wrote: > > I was wondering if you could just clarify how I might convert a standard > model object into a flask-sqlalchemy model object.
why do you need to do this ? What flask-sqlalchemy-specific features would you hope for the model objects to have ? There's pretty much two I can see - one is the MyModel.query attribute, and the other are the events. Neither are necessary, though you might want the usage of one or the other. Otherwise no "conversion" is needed. > > Using the two examples above, would I just take my User(Base) class and then > assign it property out of the Flask db properties? Something like: > > User.session = db.session() > User.engine = db.engine() > > I know those properties don't actually exist on User, but is that the kind of > thing I should be looking to do? Move certain pieces into all of the models? > or is there something higher level going on that will do this for me in some > way? something else? I don't see why engine or session would be stuck onto the model class like that, I don't see that usage here: http://packages.python.org/Flask-SQLAlchemy/quickstart.html#a-minimal-application. Just the "query" attribute. "User.query.all()". This is equivalent to "session.query(User).all()". The "User.session / User.engine" pattern suggests that a model class acts as a registry for how to get at a live database connection. That pattern is one that SQLAlchemy specifically discourages. In the Flask docs, you'll see that the "handle" to the state of a transaction is db.session. The objects like instances of User are then contained within that. > > This seems like it would be a really good way to accomplish what I'm looking > for and to move things forward as well. Once I read up on the requisite > knowledge I may end up making an attempt at making this over the next little > while. I had a drink with Armin last week and I'm not sure if his current > stuff points him in this direction (of course you'd have to ask him for the > real answer on that), but I certainly have a vested interest, so maybe I can > do some of the grunt work. its really quite a small amount of effort. I think for now the strategy on your end should be to forge ahead with what's there, and if there's some very specific thing that doesn't work as you expect, I can show you how to get the behavior you're looking for. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.