objectscript

How do you cycle through items in a Relationship?


This is the current code:

Class %Utcov.Test Extends %RegisteredObject
{

ClassMethod listClasses(ns As %String, projectName As %String)
{
    // Switch namespaces to the new one
    new $namespace
    set $namespace = ns

    // Grab our project, by name; fail otherwise
    // TODO: failing is CRUDE at this point...
    #dim project as %Studio.Project
    #dim status as %Status

    // TODO: note sure what the "concurrency" parameter is; leave the default
    // which is -1
    set project = ##class(%Studio.Project).%OpenId(projectName, /* default */, .status)

    if ('status) {
        write "Argh; failed to load", !
        halt // meh... Ugly, f*ing ugly
    }

    w project.Items
}

ClassMethod main()
{
    do ..listClasses("USER", "cache-tort-git")
}

}

First things first: I know that the code sucks... But that's the learning curve, I will eventually do better... The problem I want to solve here is this line:

w project.Items

At the console, it currently prints:

2@%Library.RelationshiptObject

but what I'd like to do is of course to cycle through these objects, which, according to the documentation, are "instances" of %Studio.ProjectItem.

How do I cycle through these? WRITE doesn't cut it, and in fact I surmised from the start that it would not... I just cannot figure out how this is done in ObjectScript :/


Solution

  • When your writed object with w project.Items, you got such string 2@%Library.RelationshiptObject, this string may help in understanding what the object we got, and in this case it is an object of class %Library.RelationshiptObject, when you open this class in documentation, you may find some methods which could help you.
    Here you can find some examples, how to work with relationships, in objects way and with sql.