[sqlalchemy] Re: table union through ORM

2008-05-06 Thread Michael Bayer


On May 6, 2008, at 7:49 AM, Eric Lemoine wrote:


 Hello

 Here's my thing:

 I have two DB tables, refugees and offices, which are independent
 tables (no foreign key). I already have two mappers for those tables:

 mapper(Refugee, refugees_table)
 mapper(Office, offices_table)

 In addition to being able to do independent queries on each table, I'd
 like to do queries in both tables (UNION) and get results in objects
 of type Location (a Python class of my own). In other words, I'd like
 to do queries using session.query(Location).

 I've tried various things (Mapping a Class against Multiple Tables in
 the doc in particular), but with no luck.

 Does anyone have suggestions?


this would be concrete table inheritance:  
http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_inheritance_concrete

Both Refugee and Office would need to include Location as at least  
one of their base classes.

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



[sqlalchemy] Re: table union through ORM

2008-05-06 Thread Eric Lemoine

On Tue, May 6, 2008 at 4:24 PM, Michael Bayer [EMAIL PROTECTED] wrote:



  On May 6, 2008, at 7:49 AM, Eric Lemoine wrote:

  
   Hello
  
   Here's my thing:
  
   I have two DB tables, refugees and offices, which are independent
   tables (no foreign key). I already have two mappers for those tables:
  
   mapper(Refugee, refugees_table)
   mapper(Office, offices_table)
  
   In addition to being able to do independent queries on each table, I'd
   like to do queries in both tables (UNION) and get results in objects
   of type Location (a Python class of my own). In other words, I'd like
   to do queries using session.query(Location).
  
   I've tried various things (Mapping a Class against Multiple Tables in
   the doc in particular), but with no luck.
  
   Does anyone have suggestions?


  this would be concrete table inheritance:  
 http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_inheritance_concrete

  Both Refugee and Office would need to include Location as at least
  one of their base classes.

In the Concrete Table Inheritance example in the doc, there's an
employee table. In my case, there's no location table, and that's
why I haven't seen Concrete Table Inheritance as my case's solution.
So I'm still confused on how I'm going to achieve what I want.

Thanks a lot,

--
Eric

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



[sqlalchemy] Re: table union through ORM

2008-05-06 Thread Michael Bayer


On May 6, 2008, at 11:13 AM, Eric Lemoine wrote:


 In the Concrete Table Inheritance example in the doc, there's an
 employee table. In my case, there's no location table, and that's
 why I haven't seen Concrete Table Inheritance as my case's solution.
 So I'm still confused on how I'm going to achieve what I want.


you wouldnt have the location table, and the Location mapper would  
be mapped directly to the polymorphic union , i.e. mapper(Location,  
pjoin).

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



[sqlalchemy] Re: table union through ORM

2008-05-06 Thread Eric Lemoine

Thanks a lot. I'll try that

2008/5/6, Michael Bayer [EMAIL PROTECTED]:


 On May 6, 2008, at 11:13 AM, Eric Lemoine wrote:

 
  In the Concrete Table Inheritance example in the doc, there's an
  employee table. In my case, there's no location table, and that's
  why I haven't seen Concrete Table Inheritance as my case's solution.
  So I'm still confused on how I'm going to achieve what I want.


 you wouldnt have the location table, and the Location mapper would
 be mapped directly to the polymorphic union , i.e. mapper(Location,
 pjoin).

 


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



[sqlalchemy] Re: table union through ORM

2008-05-06 Thread Eric Lemoine

On Tue, May 6, 2008 at 5:36 PM, Eric Lemoine [EMAIL PROTECTED] wrote:
 Thanks a lot. I'll try that

It works great! I would never have found how to do it without support
from you Michael. The doc wasn't explicit enough for me to figure it
out by myself. But support on the mailing list is awesome as usual.
Thanks again,

--
Eric

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