Adam Tauno Williams wrote: > But I have one 1:1 relation in my database that would be much easier to > model as just one object. > > job_history job_history_info > --------------- ---------------------------- > job_history_id (PK) <-1:1-> job_history_id > object_version job_history_info_id (PK) > job_id comment > actor_id db_status > action > action_date > job_status > db_status >
if you create Table objects for job_history and job_history_info, you can create a join via job_history.join(job_history_info), and then specify that to a declarative class using "__table__ = <myjoin>" instead of __tablename__. you will also want to equate job_history_id in both tables to a single attribute, as in http://www.sqlalchemy.org/docs/05/mappers.html#mapping-a-class-against-multiple-tables , which is accomplished with declarative in a similar way, i..e. "id = [job_history.c.job_history_id, job_history_info.c.job_history_id". > > Is there, in general, a way to specify that a join is 1:1 so that the > mapper property returns the entity on the other side of the join rather > than a single element array? a map to a join is always "1:1" from the object perspective, but if there are multiple job_history_info rows for one job_history row, those would typically be expressed as different identities within the mapping. the primary key of your mapping defaults to [job_history.job_history_id, job_history_info.job_history_info_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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---