Nevermind... got it. Thanks for your help!
I couldn't really tell whether you'd be interested adding this feature
to the product? I didn't especially like that I needed to override
RelationshipProperty._get_context_strategy() without being able to
invoke super()._get_context_strategy() because my code needed to be mid
method.
You might have a better way:
class RelationshipProperty()
....
def _get_context_strategy(self, context, path):
# note: slight changes here with newer sqla version....
cls = context.attributes.get(('loaderstrategy',
_reduce_path(path)), None)
if not cls and \
context.attributes.get('_lazyload_others') and \
isinstance(self.strategy, (strategies.SubqueryLoader,
strategies.EagerLoader)):
cls = strategies.LazyLoader
if cls:
return self._get_strategy(cls)
else:
return self.strategy
As a side note, interfaces.py StrategizedProperty's has copied code that
seems redundant to me:
def _get_context_strategy(self, context, reduced_path):
key = ('loaderstrategy', reduced_path)
if key in context.attributes:
cls = context.attributes[key]
try:
return self._strategies[cls]
except KeyError:
return self.__init_strategy(cls)
else:
return self.strategy
def _get_strategy(self, cls):
try:
return self._strategies[cls]
except KeyError:
return self.__init_strategy(cls)
This can be simplified to:
def _get_context_strategy(self, context, reduced_path):
key = ('loaderstrategy', reduced_path)
if key in context.attributes:
self._get_strategy(context.attributes[key]) # <=========
else:
return self.strategy
def _get_strategy(self, cls):
try:
return self._strategies[cls]
except KeyError:
return self.__init_strategy(cls)
On 12/17/2011 2:35 PM, Kent wrote:
How do I get the attribute to copy to a subquery's query._attribute ?
I need it to be a MapperOption and that should then copy itself via q
= q._conditional_options(*orig_query._with_options)?
(This doesn't seem like it needs be a MapperOption, or do you think it
should be? Not quite sure why not just a query method like
enable_eagerloads().... it needs no path information.
if you want a Query to lazyload everything by default then the
_get_context_strategy(), or some system around it (I don't have the
time to look at the source right now) needs to be changed to
recognize some kind of "wildcard" - right now a MapperOption puts a
key that is along the lines of (MyClass.somerelation, "eager") into
attributes - so it would be like ("*", "lazy"). This is not how it
actually looks but the idea would be along those lines.
--
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.