[Helma-user] difficult object relational mapping

Maksim Lin for technical support mailling lists maksim_lin at ngv.vic.gov.au
Wed Mar 5 23:06:47 CET 2008


I think what what Breton was suggesting was not having a collection at
all.
The idea is that you suggest use helma.Database to do whatever
super-complex query you need that just returns the IDs of whatever
Prototype you want and then you just loop through those ids to build a
simple JS array of the HopObjects and return them.
for example:

function getEventsByRecentChanges() {

	var sqlResult =
helma.Database.getInstance("MyDataSource").query("SELECT ID from ...);
	var resultList = [];
	for (var i=0; i < sqlResults.length; i++) {
		resultList.push( Event.getById(sqlResult.[i].ID) );
	}
	return resultList;
}
 
voila!
the above method pretty much gives you the same as
root.recentEvents.list(), ie. an array of the Hopobjects that you need,
sorted in the correct order. And as Breton mentioned, helma cache pretty
much will make sure that you don't even generate any more DB traffic if
you already have all the Event objects in the cache already.

I am hoping that the promised generic query interface design in the wiki
would work on the same lines, just letting you define the above with
simple javascript properties rather then having to drop into SQL
*especially* since it would be nice to also have an implementation which
worked with the builtin DB, in which case of course dropping in some sql
is not an option :-)

Maks.

> -----Original Message-----
> From: helma-user-bounces at helma.org 
> [mailto:helma-user-bounces at helma.org] On Behalf Of Joshua Paine
> Sent: Thursday, 6 March 2008 08:49
> To: Helma User Mailing List
> Subject: Re: [Helma-user] difficult object relational mapping
> 
> Breton Slivka wrote:
> > A simpler way you might do it...
> 
> As you say, this probably wouldn't be outrageously slow, but 
> it would mean that the collection wasn't ordered correctly 
> and you'd have to work with it differently from any other 
> collections in the app.
> 
> Slightly faster to implement, perhaps (if you're not quick 
> with writing database triggers), but the added inconsistency 
> in the app would not be worth it IMO.
> _______________________________________________
> Helma-user mailing list
> Helma-user at helma.org
> http://helma.org/mailman/listinfo/helma-user
> 


More information about the Helma-user mailing list