OK ... I found orm.aliased() which seems to do what I want to do, I have
the following :

>>> images = File.query().join(Mime).join(MimeMajor)\
.filter_by(major='image').subquery()

>>> mapped_image = orm.aliased(File, images)

>>> q = Session.query(Content).with_polymorphic([Folder, mapped_image])

however, when I :

>>> print q
SELECT content.id AS content_id, content.added AS content_added,
content.updated AS content_updated, content.title AS content_title,
content.description AS content_description, content.effective AS
content_effective, content.expiration AS content_expiration,
content.content_type_id AS content_content_type_id, content.container_id
AS content_container_id, content.weight AS content_weight,
content.exclude_nav AS content_exclude_nav, folder.content_id AS
folder_content_id, data.content_id AS data_content_id, data.mime_id AS
data_mime_id, data.file_size AS data_file_size, data.name AS data_name 
FROM content LEFT OUTER JOIN folder ON content.id = folder.content_id
LEFT OUTER JOIN data ON content.id = data.content_id

I don't understand why SQLAlchemy "LEFT OUTER JOIN data" instead of my
subselect (in images) .. ? 

I'd like to SELECT ... FROM content LEFT OUTER JOIN folder on ... LEFT
OUTER JOIN (SELECT .. FROM data JOIN ... JOIN ... WHERE ...) as ...

Thanks,
Julien


On Mon, 2009-07-06 at 13:42 +0200, Julien Cigar wrote:
> Hello,
> 
> Any idea with the following query : 
> 
> Session.query(Folder, Data).
>  select_from(folder.join(content).outerjoin(data.select().alias('foo')))
> 
> why SQLAlchemy generates :
> 
> SELECT ... 
> FROM data, folder JOIN content ON content.id = folder.content_id LEFT
> OUTER JOIN (SELECT data.content_id AS content_id, data.mime_id AS
> mime_id, data.file_size AS file_size, data.name AS name 
> FROM data) AS foo ON content.id = foo.content_id
> 
> instead of
> 
> SELECT ...
> FROM folder JOIN content ON content.id = folder.content_id LEFT OUTER
> JOIN (SELECT data.content_id AS content_id, data.mime_id AS mime_id,
> data.file_size AS file_size, data.name AS name 
> FROM data) AS foo ON content.id = foo.content_id
> 
> Is there a way to tell SQLAlchemy that it should map "Data" with the
> result from the subquery (foo) instead of adding the table in the FROM ?
> 
> Thanks,
> Julien
> 
> 
-- 
Julien Cigar
Belgian Biodiversity Platform
http://www.biodiversity.be
Université Libre de Bruxelles (ULB)
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
Mail: jci...@ulb.ac.be
@biobel: http://biobel.biodiversity.be/person/show/471
Tel : 02 650 57 52


--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to