[sqlalchemy] relationships for no-table-related Class

2010-11-11 Thread neurino
I have a tree structure Root | +--Area || |+--SubArea ||| ||+--Item ||| ||+--Item || |+--SubArea | | | +--Item | | | +--Item | +--Area | +--SubArea || |

[sqlalchemy] Re: Delete and Concrete Table Inheritance

2010-11-11 Thread Mene
Yes, that was what I searched for. My Solution now is to use pythons introspection like this: for dataClass in Master.__subclasses__(): table = sqlalchemy.orm.class_mapper(dataClass).local_table delete_query = table.delete(). \ where(...) session.execute(delete_query,

[sqlalchemy] how to graph database structure?

2010-11-11 Thread Nagy Viktor
Hi, I've reflected a database, and it would like to get a graphic representation of it something like the graph_models command in django command extensions. The best would be if the tool could create the graphics without a database connection, simply using my metadata for example. I've googled

Re: [sqlalchemy] how to graph database structure?

2010-11-11 Thread Tamás Bajusz
On Thu, Nov 11, 2010 at 12:59 PM, Nagy Viktor viktor.n...@toolpart.hu wrote: Hi, I've reflected a database, and it would like to get a graphic representation of it something like the graph_models command in django command extensions. The best would be if the tool could create the graphics

[sqlalchemy] Two relationships with a same backref name. Is that (even) possible or I got everything wrong?

2010-11-11 Thread Hector Blanco
I have a class that has two relationships to the same type of objects. One of the relationships will store objects of type VR and the other objects with a type CC. One object can only be in one of the lists (relationships) at the same time: This is the container class and its two relationships:

Re: [sqlalchemy] Re: Odd many-to-one problem

2010-11-11 Thread Mike Conley
For cases like this I have found something like this to be useful http://www.sqlalchemy.org/docs/orm/relationships.html#multiple-relationships-against-the-same-parent-child using lazy loading and viewonly=True as needed I found this to be clearer than column property because it fits cleanly

[sqlalchemy] Re: Odd many-to-one problem

2010-11-11 Thread Jonathan Gardner
relationship() expects a class or a mapper instance, not a string. I got this error: ArgumentError: relationship 'available_deals' expects a class or a mapper argument (received: type 'str') On Nov 10, 4:46 pm, Sergey V. sergey.volob...@gmail.com wrote: The twist is that I've spread out my

[sqlalchemy] Re: Odd many-to-one problem

2010-11-11 Thread Jonathan Gardner
That is useful for mapping single or combined columns to an attribute. Here, I want to map entire objects. On Nov 10, 10:20 pm, Eric Ongerth ericonge...@gmail.com wrote: Good point, Sergey. Here is the relevant documentation regarding mapping attributes to

[sqlalchemy] Re: Odd many-to-one problem

2010-11-11 Thread Jonathan Gardner
This is what I need to do, except the Merchant object is defined before the Deal object. In the example in the documentation, I have mapped User before I have mapped Address. On Nov 11, 10:25 am, Mike Conley mconl...@gmail.com wrote: For cases like this I have found something like this to be

Re: [sqlalchemy] Re: Odd many-to-one problem

2010-11-11 Thread Mike Conley
If it's simply a matter of sequence of how code is organized: 1. Define Merchants table and mappers 2. Define Deals table and mappers 3. Add relations to Merchant All of this can be in separate files if needed; just import right definitions where needed. metadata = MetaData() merchants =

[sqlalchemy] Re: Odd many-to-one problem

2010-11-11 Thread Sergey V.
relationship() expects a class or a mapper instance, not a string. I got this error: ArgumentError: relationship 'available_deals' expects a class or a mapper argument (received: type 'str') Hmm... I'm not sure what I'm doing wrong but passing strings to relation() definitely works for me:

[sqlalchemy] Re: Two relationships with a same backref name. Is that (even) possible or I got everything wrong?

2010-11-11 Thread Eric Ongerth
Hi Hector, If I'm not mistaken, everywhere you wrote (MyObject.id==MyObject.containerId), you meant to write: (Container.id==MyObject.containerId). Instead of the backref technique, why not just create the MyObject-- Container relationship a single time in your MyObject class. That should be

[sqlalchemy] Re: Odd many-to-one problem

2010-11-11 Thread Eric Ongerth
Mike, what you set forth is more of what I was actually trying to bring into the discussion (having used that same technique myself), rather than the link I gave above. I need to get more sleep and check my doc references more carefully! On Nov 11, 1:39 pm, Mike Conley mconl...@gmail.com wrote: