assign_mapper is doing five different things:
1 Hide the session context and session
2 .query()
3 shadowed query methods (get*/select*/count/join*/etc)
4 shadowed session methods (flush/delete/save/etc)
5 connecting a DynamicMetaData whenever it needs to
(1) we all agree is very useful.
(2) is more straightforward to the user than session.query(MyClass).
(3) is under probation.
(4) I haven't used so I'm not sure if it's better or worse than
session.* . But grafting fewer rather than more methods onto the
mapped class makes sense.
(5) is maybe being done by the session_context rather than
assign_mapper, so perhaps it doesn't apply here. I just saw a Pylons
recipe that said you can use a DynamicMetaData in your model *if* you
use assign_mapper; I'm not sure why.
http://docs.pythonweb.org/display/pylonscookbook/SQLAlchemy+for+people+in+a+hurry
Given that all this is in control of the session_context, why not make
assign_mapper a method of it, with boolean flags to enable method
decoration:
session_context.map(MyClass, table, query_methods=True, session_methods=True)
or:
session_context.query_methods = True
session_context.session_methods = True
session_context.map(MyClass, table)
If we hang the query methods off .query(), can we hang the session
methods off .session()? Or .store. (But not .objectstore, ugh.)
Michael Bayer wrote:
> as it turns out, assign_mapper's monkeypatched methods (and they are
> all monkeypatched, not sure why you singled out query())
.query() is a class method that's actually a lambda. Very strange.
The other methods looked like they were assigned more
straightforwardly but maybe that's just a superficial appearance.
They don't use lambdas though.
--
Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---