Re: [Modeling-users] Lazy Relation Initialisation
Status: Abandoned
Brought to you by:
sbigaret
|
From: Sebastien B. <sbi...@us...> - 2003-06-19 11:57:00
|
Yannick Gingras <yan...@sa...> wrote:
> Hi,=20
> As I understand (looking at my bandwidth monitor), to-many relations
> are lazily retrieved.
>=20
> ex:=20
> myBooks =3D meAsAnAuthor.getBooks() # does not fetch anything=20
> for book in myBooks: # fetch a record from the DB each loop
> print book.getTitle()
>=20
> Is there a way to have to fetch the complete meAsAnAuthor with all
> it's books once to avoid the connection latency of a fetch for each
> book ?
Could you be more specific? For example, by setting
MDL_ENABLE_DATABASE_LOGGING and reporting the fetch you see for each loop? =
The
framework normally fetches all the books when the array is first accessed, =
and
if you find an exception to this rule this is definitely a bug. Here,
accessing the array is first done when iterating on it in the for statement.
This is what I expect (and actually get here) for this code:
ec=3DEditingContext()
qualifier=3DqualifierWithQualifierFormat('lastName=3D=3D"Dard"')
fetchSpec=3DFetchSpecification('Writer', qualifier)
dard=3Dec.objectsWithFetchSpecification(fetchSpec)[0]
idx=3D1
myBooks=3Ddard.getBooks()
print '### before loop'
for book in myBooks:
print '### loop: %i, title: %s'%(idx,book.getTitle())
idx+=3D1
I get (stripping unnecessary log msgs):
Evaluating: SELECT t0.ID, t0.FIRST_NAME, t0.LAST_NAME, t0.AGE, t0.BIRTHDAY,=
t0.FK_WRITER_ID FROM WRITER t0 WHERE t0.LAST_NAME =3D 'Dard'
rowcount: 1 Returning: {'id': 3, 'age': 82, 'lastName': 'Dard', 'FK_Writer_=
id': 2, 'firstName': 'Frederic', 'birthday': <DateTime object for '1921-06-=
29 04:56:34.00' at 81699f0>}
### before loop
Evaluating: SELECT t0.id, t0.title, t0.FK_WRITER_ID, t0.PRICE FROM BOOK t0 =
WHERE (t0.FK_WRITER_ID =3D 3)
rowcount: 3 Returning: {'title': 'Bouge ton pied que je voie la mer', 'id':=
2, 'price': None, 'FK_Writer_Id': 3}
rowcount: 3 Returning: {'title': 'Le coup du pere Francois', 'id': 3, 'pric=
e': None, 'FK_Writer_Id': 3}
rowcount: 3 Returning: {'title': "T'assieds pas sur le compte-gouttes", 'id=
': 4, 'price': None, 'FK_Writer_Id': 3}
rowcount: 3 Returning: None
### loop: 1, title: Bouge ton pied que je voie la mer
### loop: 2, title: Le coup du pere Francois
### loop: 3, title: T'assieds pas sur le compte-gouttes
-- S=E9bastien.
|