On Mar 5, 2011, at 10:37 AM, Kent wrote:
> Oracle 8 strikes again. But our client's current legacy application
> requires it (until we can get them off the app).
>
> Anyway, when Oracle 8 is detected, I wish to convert certain mapper
> properties' lazy attribute from False => 'subquery' because oracle 8
> isn't smart enough to run the query anywhere near efficiently (but 9i
> is).
>
> So, after all the mappers are compiled (I need backrefs also), I'm
> looping through the _mapper_registry and detecting which properties
> need to be converted if the oracle is 8i.
>
> Unfortunately for me:
> prop.lazy = 'subquery'
> prop.strategy_class = strategies.factory('subquery')
>
> isn't enough because the prop.strategy was already initialized I
> surmise.
>
> Because of potential circular references and complications with
> backrefs and future mapped classes not being mapped to a table until
> after mapper() is invoked for the class, I do not think I can figure
> out whether lazy should be False vs. 'subquery' during the mapper()
> invocation...(at least trivially), so I am waiting until after all
> mappers are compiled.
>
> Can you think of any solutions for me? Any way to change a properties
> lazy attribute after it's been instantiated? Any way to clone the
> property and replace it with a new one with a difference lazy
> attribute?
If it were me I'd still try to solve the problem of deciding which
relationships/backrefs need the setting up front. You can limit it to those
who are setting up lazy="joined" I assume, and i'd consider getting ugly too
with some hardcoding, since this is for legacy support anyway.
Otherwise the internal API magic you need would be:
from sqlalchemy.orm.interfaces import StrategizedProperty
prop.strategy_class = strategies.factory('subquery')
StrategizedProperty.do_init(prop)
which would reset the "self.strategy" attribute and the collection of alternate
strategies.
--
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.