Hello all;

I am trying to do a subselect on an Outer join.  I have a table of
votes that can apply to multiple objects in my system so their is no
direct foreign key. A Voteable type implementation.   When i load the
list of Projects, i want to return the current users votes eagerly if
possible, but if they haven't voted still return the project.

It is similar to the Association examples, or this example:
http://techspot.zzzeek.org/?cat=3

With the difference being that its possible that the associated table
won't have any, in which case it still needs to return the parent
table, I can't get this accomplished.   Currently i have written the
SQL by hand, and am loading it into a secondary mapper, but it breaks
with "Could not find any Tables in the mapped object".  I have tried a
variety of things before that with less success.

Any suggestions would be appreciated.

Thank You.
Aaron

project_table = Table("project", metadata,
        Column("id", Integer, primary_key=True),
        Column("title", String(255), nullable=False),
        Column("createdby_id", Integer),
        Column("rating_ct", Integer, default=0),
    )
# ratings
rating_table = Table("vote", metadata,
        Column("id", Integer, primary_key=True),
        Column("person_id", Integer),
        Column("entry", Integer),
        Column("obj_id", Integer),
    )


#  This is the SQL that works by hand

SELECT project.id AS project_id, project.title AS project_title,
    project.createdby_id AS project_createdby_id,
    project.vote_ct AS project_vote_ct,
    vote_der.vote_id, vote_der.vote_person_id,
    vote_der.vote_entry, vote_der.vote_obj_id
FROM project LEFT OUTER JOIN (
        SELECT     vote.id AS vote_id, vote.person_id AS
vote_person_id,
        vote.entry AS vote_entry, vote.obj_id AS vote_obj_id FROM vote
where person_id = 24
    ) AS vote_der
 ON project.id = vote_der.vote_obj_id


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to