[Modeling-users] Fetching relationships in batch
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2003-07-14 19:40:49
|
Hi, Given the recent discussion we had w/ Yannick on to-many faults being triggered even when all te related objects were previously fetched, here is a first implementation of DatabaseContext.batchFetchRelationship() You'll find the patch at: https://sourceforge.net/tracker/index.php?func=3Ddetail&aid=3D771009&group_= id=3D58935&atid=3D489337 While it's quite naive for the moment being, it is completely usable. Current limitations: it can only acts on to-many relationships, and these to-many rels should have an inverse to-one relationship. Usage (this is NOT the definitive API that will be exposed to users ;) ----- Say you have Company.toPersons <---->> Person.company 1. fetch the companies you want, 2. use this: >>> from Modeling.ModelSet import defaultModelSet >>> dbContext=3DdatabaseContext('Company', ec) >>> rel=3DdefaultModelSet().entityNamed('Company').relationshipNamed('perso= ns') >>> dbContext.batchFetchRelationship(rel, companies, ec) given that databaseContext() is: def databaseContext(entityName, ec): from Modeling.FetchSpecification import FetchSpecification fs=3DFetchSpecification(entityName) return ec.rootObjectStore().objectStoreForFetchSpecification(fs) 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? -- S=E9bastien. |