Search code examples
objectlsfusion

Obtaining an object identifier in lsfusion


I have a Document class and I have assigned a unique identifier to each object in that class. But I cannot understand how to get the document by its id?

CLASS Document;
id(Document d) = DATA INTEGER (Document);

Solution

  • You can do this using GROUP operator:

    document(id) = GROUP MAX Document d BY id(d);
    

    or alternatively:

    document(id) = GROUP AGGR Document d BY id(d);
    

    In the latter example a constraint on the uniqueness of the id will be created. This will result in an error message if you try to create two documents with the same identifier.