What is the efficient way to generalize such joins, If I am parsing a graph 
and get the joins dynamically? 

On Wednesday, February 7, 2018 at 1:09:42 PM UTC-6, madhusud...@gmail.com 
wrote:
>
> Thank you, Could you elaborate on how would I "constrain the selection 
> with joins to node1 and node3"?
> I am still not clear on that part.
>
>
> On Wednesday, February 7, 2018 at 12:57:59 PM UTC-6, Jonathan Vanasco 
> wrote:
>>
>> I do a lot with graphs in SqlAlchemy, and I think you'd have a easier 
>> time writing these queries if you flipped your search so that you're 
>> querying a single identified object.
>>
>> For example, on use-case-1, you can query for the "Usage", and join the 
>> nodes.
>>
>>> result = session.query(Usage)\
>>> .join(node_1, Usage.first_id == node_1.id)\
>>> .join(node_2, Usage.second_id, node_2.id)\
>>> .options(sqlalchemy.orm.containseager('orl1', aliased=node_1),
>>> sqlalchemy.orm.containseager('orl2', aliased=node_2),
>>> )\
>>> .first()
>>>
>>>
>> Using that approach, on use-case-2, you can query for the "Node2 " 
>> object, and constrain the selection with joins to node1 and node3.
>>
>> You can definitely use your current approach, but a lot of "complicated" 
>> joins in SqlAlchemy are **much** simpler when the primary thing you query 
>> is not what you would naturally think to query of in raw sql - but 
>> something more convenient for how the necessary joins and relationships are 
>> constructed.
>>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to