On Sep 6, 2010, at 9:06 AM, Kent wrote:

> with_parent seems to add a join condition.  Is there a way to get at
> the query object that would be rendered from a lazy load (or what
> "subqueryload" would render on the subsequent load), but on a
> transient object, if i supply the session?

with_parent() uses the same code that the lazy loader uses, which does not 
render the parent table (if thats the join you are referring to).   If you say 
query(Child).with_parent(Parent, 'child'), you should get the exact same thing 
as if you said Parent.child.

However I just tried it and, like the lazy loader, its using the "committed" 
value of the id attributes, so again this is not workable for transient 
attributes (so not sure how you are even using it).


> 
> even though not "recommended", can it make sqla believe my transient
> object is detached by setting its state key?

The state.key, plus session_id otherwise its detached.  But also the id/foreign 
key attributes need to have a "committed" value, so your object would be pretty 
much not persistable at that point until you reversed all that and it's looking 
like a pretty nasty hack.   Would be easier to just create a userland version 
of strategies.LazyLoader.lazy_clause since you're really looking for SQL 
generation here, not object state hackage.

> 
> There are reasons i do not want to add this to the session and
> disabling autoflush would also cause problems.

if these reasons could be described I would be able to consider what feature 
you might really need here.     Most expedient would be that with_parent() 
detects if the object is transient and sends through flags so that the 
"transient" attribute values are used within lazy_clause().


> 
> 
> 
> On Sep 3, 9:58 am, Michael Bayer <mike...@zzzcomputing.com> wrote:
>> On Sep 3, 2010, at 9:36 AM, Kent wrote:
>> 
>>> For the case of customerid = '7', that is a simple problem, but when
>>> it is a more complex join condition, we only wanted to define this
>>> condition in one single place in our application (namely, the orm).
>>> That way, if or when that changes, developers don't need to search for
>>> other places in the app that needed to manually duplicate the logic of
>>> the orm join condition.
>> 
>>> If I supplied the DBSession to sqla, it would know how to create the
>>> proper Query object for this lazyload.  Can you point me in the right
>>> direction (even if where you point me is not currently part of the
>>> public API)?
>> 
>> Query has the with_parent() method for this use case.  
>> 
>> 
>> 
>> 
>> 
>>> Thanks again,
>>> Kent
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "sqlalchemy" group.
>>> To post to this group, send email to sqlalch...@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> sqlalchemy+unsubscr...@googlegroups.com.
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/sqlalchemy?hl=en.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.

Reply via email to