Re: [Modeling-users] Fetching relationships in batch
Status: Abandoned
Brought to you by:
sbigaret
|
From: Sebastien B. <sbi...@us...> - 2003-07-14 21:33:07
|
Yannick Gingras <yan...@sa...> wrote:
> On July 14, 2003 03:40 pm, Sebastien Bigaret wrote:
> > With this you'll get only 2 fetches: one for the master (companies),
> > one for the slaves (related persons).
> >
> > Yannick, could you try this and report please?
>=20
> Looking at the patch it is unclear to me if I can mix it with the
> rawRow fetch one :
>=20
> dst_objs=3Dec.fetch(aRelationship.destinationEntityName(), q)
>=20
> Given the option I will rater take the rawRow fetch and manage the
> relation by hand but I know that my case is a bit special.
No, you need real objects to use batchFetchRelationship(), since its purpose
is to populate the to-many relationships with their related objects in a
single fetch.
However, you can either
* turn a raw row (dictionary) into a real object w/ something like:
>>> import AuthorBooks
>>> from Modeling.EditingContext import EditingContext
>>> ec=3DEditingContext()
>>> rows=3Dec.fetch('Writer', 'firstName=3D=3D"John"', rawRows=3D1)
>>> an_author=3Drows[0] # dictionary
>>> pprint.pprint(an_author)
{'FK_Writer_id': 2,
'age': 82,
'birthday': <DateTime object for '1921-06-29 04:56:34.00' at 84e33f0>,
'firstName': 'Frederic',
'id': 3,
'lastName': 'Dard'}
>>> author_pk_name=3D'id'=20
>>> from Modeling.GlobalID import KeyGlobalID
>>> gid_author=3DKeyGlobalID('Writer',
... {author_pk_name: an_author[author_pk_name]})
>>> real_author=3Dec.faultForGlobalID(gid_author, ec)
>>> print real_author.getFirstName(),real_author.getLastName(),real_aut=
hor
Frederic Dard <Writer.Writer instance at 0x84d829c>
Note: this is just a quick hint: when it is integrated in cvs, you'll then
just ask:
ec.faultForRawRow(an_author, 'Writer')
instead of all these things.
* or simply fetch the related objects (either real object or raw rows), s=
ay
Writer, by using a qualifier like=20
'books.FK_Writer_Id =3D=3D %i' % an_author['id']
(of course, this implies you use information from your model, such as t=
he
PK or FK names)
Okay, enough w/ this, time for the fireworks now ;)
-- S=E9bastien.
PS: BTW, the fetch API will probably be changed w/ 'rowRaws=3D' (instead of
'rawRow=3D', w/o an 's') --I meant it, yet another typo!
|