On Tue, 2009-10-06 at 09:56 -0400, Michael Bayer wrote:
> 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].

Ok, I've spent quite a bit of time trying to get this do work.  And I've
completely failed!   I've searched the Internet high-and-low and cannot
find a *single* example of such a joined entity using the declarative
syntax, anywhere.

If someone is willing to make a working example of this [I'll write-up a
detailed description] joining these two tables as one entity I'll (a)
send you $50US via paypal, post the example back here, and to my BLOB
(license: MIT/X11).

-- 
OpenGroupware developer: [email protected]
<http://whitemiceconsulting.blogspot.com/>
OpenGroupare & Cyrus IMAPd documenation @
<http://docs.opengroupware.org/Members/whitemice/wmogag/file_view>

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to