[sqlalchemy] Re: Automatic Polymorphic Identity Assignment

2009-09-09 Thread gizli
Found two ways of doing this: 1. use metaclass: from sqlalchemy.ext.declarative import DeclarativeMeta class PolymorphicSetter(DeclarativeMeta): def __new__(cls, name, bases, dictionary): if '__mapper_args__' in dictionary.keys(): dictionary['__mapper_args__']['polymorph

[sqlalchemy] Re: Somewhat complex union_all() question

2009-09-09 Thread Mike Conley
here is the sample code I am using http://pastebin.com/m6cd9c5dd -- Mike Conley On Wed, Sep 9, 2009 at 11:10 PM, Mike Conley wrote: > On Wed, Sep 9, 2009 at 10:46 PM, Michael Bayer > wrote: > >> >> >> On Sep 9, 2009, at 8:41 PM, Seth wrote: >> >> > >> > Ok Mike, >> > >> > Tell me what yo

[sqlalchemy] Re: Somewhat complex union_all() question

2009-09-09 Thread Mike Conley
On Wed, Sep 9, 2009 at 10:46 PM, Michael Bayer wrote: > > > On Sep 9, 2009, at 8:41 PM, Seth wrote: > > > > > Ok Mike, > > > > Tell me what you think about this: > > > > q1 = DBSession.query(P1.id, P1.user_id, P1.type, P1.title, P1.body, > > P1.created, P1.updated) > > q2 = DBSession.query(P2.id,

[sqlalchemy] Re: Automatic Polymorphic Identity Assignment

2009-09-09 Thread gizli
Thanks for the suggestion Wolodja but I dont think that would work. The self object is not defined at the time of class loading in python: >>> class Test: ... qq = self.__class__.__name__ ... def fu(self): ... print "fu" ... Traceback (most recent call last): File "", line 1

[sqlalchemy] Re: Somewhat complex union_all() question

2009-09-09 Thread Michael Bayer
On Sep 9, 2009, at 8:41 PM, Seth wrote: > > Ok Mike, > > Tell me what you think about this: > > q1 = DBSession.query(P1.id, P1.user_id, P1.type, P1.title, P1.body, > P1.created, P1.updated) > q2 = DBSession.query(P2.id, P2.user_id, "'P2'", P2.title, P2.body, > P2.created, P2.updated) > q3 = DBSe

[sqlalchemy] Re: Somewhat complex union_all() question

2009-09-09 Thread Mike Conley
Nothing hackish about it. The SQL is doing exactly what you want; union the posting tables and join the result to users. Simple enough that the database engine should construct a reasonable plan. -- Mike Conley On Wed, Sep 9, 2009 at 8:41 PM, Seth wrote: > > Ok Mike, > > Tell me what you thi

[sqlalchemy] Re: Somewhat complex union_all() question

2009-09-09 Thread Seth
Ok Mike, Tell me what you think about this: q1 = DBSession.query(P1.id, P1.user_id, P1.type, P1.title, P1.body, P1.created, P1.updated) q2 = DBSession.query(P2.id, P2.user_id, "'P2'", P2.title, P2.body, P2.created, P2.updated) q3 = DBSession.query(P3.id, P3.user_id, "'P3'", P3.title, P3.body, P3

[sqlalchemy] Re: Issues with layered subqueries, NOT IN, and UNION [SOLVED]

2009-09-09 Thread Seth
Mike, That's the magic I was looking for! Thank you for a more thorough explanation of the subject at hand. If the length of this thread is anyone's "fault", it would be mine for being somewhat of a SQLAlchemy newbie. I am extremely grateful for your willingness to see this thread through and I

[sqlalchemy] Re: Issues with layered subqueries, NOT IN, and UNION

2009-09-09 Thread Michael Bayer
Seth wrote: > > Michael, > > I'm really baffled by your response. Are we reading two different > threads here? Or, perhaps you missed the main message in this thread > outlining the issues with the suggestions you've given me so far? hi Seth - I was responding specifically to your example: use

[sqlalchemy] Re: Issues with layered subqueries, NOT IN, and UNION

2009-09-09 Thread Seth
Michael, I'm really baffled by your response. Are we reading two different threads here? Or, perhaps you missed the main message in this thread outlining the issues with the suggestions you've given me so far? ( direct link here: http://groups.google.com/group/sqlalchemy/msg/d4d7a958f8ac2ff8 )

[sqlalchemy] Re: Issues with layered subqueries, NOT IN, and UNION

2009-09-09 Thread Michael Bayer
Seth wrote: > > Michael, > > This is not valid SQL being outputted (at least on SQLite & MySQL). > There should not be a parenthesis between the first UNION and SELECT. > This causes an SQL error. > > Is there a way to reformat the query to get valid SQL? the results you posted do not have any pa

[sqlalchemy] Re: Automatic Polymorphic Identity Assignment

2009-09-09 Thread Wolodja Wentland
On Wed, Sep 09, 2009 at 10:14 -0700, gizli wrote: > This list has been very helpful so far, thanks a lot. I was just > wondering if there is a transparent way to assign polymorphic > identities to ORM classes using single table inheritance. Let's say we > have a base Task class: > > class Task(De

[sqlalchemy] Re: Issues with layered subqueries, NOT IN, and UNION

2009-09-09 Thread Seth
Michael, This is not valid SQL being outputted (at least on SQLite & MySQL). There should not be a parenthesis between the first UNION and SELECT. This causes an SQL error. Is there a way to reformat the query to get valid SQL? Thanks, Seth On Sep 9, 8:38 am, "Michael Bayer" wrote: > Seth wr

[sqlalchemy] Automatic Polymorphic Identity Assignment

2009-09-09 Thread gizli
Hi all, This list has been very helpful so far, thanks a lot. I was just wondering if there is a transparent way to assign polymorphic identities to ORM classes using single table inheritance. Let's say we have a base Task class: class Task(DeclarativeBase): __tablename__ = 'Tasks' id = C

[sqlalchemy] Re: Issues with layered subqueries, NOT IN, and UNION

2009-09-09 Thread Michael Bayer
Seth wrote: > > Michael, > > Once again I appreciate your help on this issue; and once again I > cannot seem to find the right recipe to get SQLAlchemy to format the > query like I want. > > I tried your latest suggestion: > users = DBSession.query(Post.id.label('post_id'), Post.user_id.

[sqlalchemy] Re: Tutorial program 'selectdemo.py'

2009-09-09 Thread Dan Presley
Thanks much! I couldn't find where that module is buried inside the documentation, hence my question. Best Regards, Dan Presley --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this

[sqlalchemy] Re: How to bypass scoped_session?

2009-09-09 Thread King Simon-NFHD78
> -Original Message- > From: sqlalchemy@googlegroups.com > [mailto:sqlalch...@googlegroups.com] On Behalf Of Eloff > Sent: 08 September 2009 21:34 > To: sqlalchemy > Subject: [sqlalchemy] Re: How to bypass scoped_session? > > > On Sep 8, 3:47 am, "King Simon-NFHD78" > wrote: > > Automa