Helma Logo
main list history
previous version  overview  next version

Version 1 by hannes on 31. March 2009, 14:45

Helma 1.7 introduces a much requested feature to create HopObject collections programmatically and on the fly, without having to define them in the prototype's *type.properties|docs/type.properties documentation* file.

HopObject constructors now have a new static getCollection() method that takes a single JS object argument. The argument contains the collection properties as you would normally define them in the _children section of the type.properties file, e.g.:

    var c = Page.getCollection({
        order: "name",
        filter: "id > 10",
    };

You can also specify the type of contained objects using the "collection" property, so the following collection is equivalent to the one defined above:

    var c = HopObject.getCollection({
        collection: "Page",
        order: "name",
        filter: "id > 10",
    };

Note that for "nested" properties such as group.order or local.1 you have to use quoted "flat" properties, not nested objects:

  var c = Page.getCollection({
      group: "author",
      "group.order": "author",
      "group.prototype": "AuthorGroup"
  });

Since I thought it would be handy, I also implemented "limit" and "offset" collection properties to implement easy pagination on dbs that support it (Postgresql and Mysql AFAIK):

http://www.sql.org/sql-database/postgresql/manual/queries-limit.html

So to fetch pages 11-20, you would do something like this:

    var q = Page.getCollection({
        limit: 10,
        offset: 10
    });

Note that "limit" is just an alias for "maxSize" introduced to be more consistent with the underlying SQL syntax. This feature is currently not supported on Oracle. If somebody can provide the SQL syntax needed to make this work on Oracle plus some testing support, I'll happily add this.

     removed
     added