On May 1, 2009, at 5:17 PM, David Gardner wrote:
> The problem I'm running into is what to pass into contains_eager().
> In my table I'm mapping a file system, Asset.path is a unique
> constraint, so my outerjoin() will either find a single row or none.
>
> When I do:
> --------------------
> scn_alias=aliased(Asset)
> p='testshow/eps/201/s22/t04'
> take = session.query(Asset).filter(Asset.path==p).\
> outerjoin((scn_alias,scn_alias.path=="%s/anim/scn"%p)).\
> options(contains_eager(Asset,alias=scn_alias)).one()
oh. contains_eager is only used for relation()s, so you'd have to
name what relation gets the collection, as in
contains_eager(Asset.something, alias=scn_alias).
>
> -----------------------
> I get:
> Traceback (most recent call last):
> File "<stdin>", line 3, in <module>
> File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/query.py", line
> 602, in options
> return self.__options(False, *args)
> File "<string>", line 1, in <lambda>
> File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/query.py", line
> 52, in generate
> fn(self, *args[1:], **kw)
> File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/query.py", line
> 619, in __options
> opt.process_query(self)
> File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/interfaces.py",
> line 655, in process_query
> self._process(query, True)
> File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/interfaces.py",
> line 661, in _process
> paths = self.__get_paths(query, raiseerr)
> File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/interfaces.py",
> line 719, in __get_paths
> raise sa_exc.ArgumentError("mapper option expects string key or
> list of attributes")
> sqlalchemy.exc.ArgumentError: mapper option expects string key or
> list of attributes
>
>
>
> Michael Bayer wrote:
>>
>> On May 1, 2009, at 2:55 PM, David Gardner wrote:
>>
>>
>>> Along those same lines, one of the things I would like to do is to
>>> do an arbitrary join, my table is hierarchical and often I want to
>>> do a join against a a node, along with another node two levels deep
>>> below it, and since its a tree structure eager loading all of the
>>> children, and grandchildren would be costly, when I only care about
>>> two of them.
>>>
>>> So I have this:
>>>
>>> scn_alias=aliased(Asset)
>>> p='testshow/eps/201/s22/t04'
>>>
>>> take = session.query(Asset).filter(Asset.path==p).\
>>> outerjoin((scn_alias,scn_alias.path=="%s/anim/
>>> scn"%p),aliased=True).one()
>>>
>>> This produces the correct SQL, but since scn_alias isn't directly
>>> mapped as a relation to the row I am querying, I can't figure out
>>> the correct arguments to pass to contains_eager().
>>>
>> contains_eager just needs to know what columns in the selectable it
>> needs to draw from. so again here, drop the aliased=True since
>> scn_alias is already an alias, then pass scn_alias as the "alias"
>> keyword to contains_eager(). Also your outerjoin should probably be
>> qualified against the parent Asset object otherwise you're in danger
>> of cartesian products.
>>
>>
>>
>>
>>
>>
>
>
> --
> David Gardner
> Pipeline Tools Programmer, "Sid the Science Kid"
> Jim Henson Creature Shop
> [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
-~----------~----~----~----~------~----~------~--~---