您如何循环浏览关系中的项目?

How do you cycle through items in a Relationship?

这是当前代码:

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")
}

}

第一件事:我知道代码很烂......但这是学习曲线,我最终会做得更好......我想在这里解决的问题是这一行:

w project.Items

在控制台,它当前打印:

2@%Library.RelationshiptObject

但我想做的当然是循环遍历这些对象,根据文档,这些对象是 "instances" of %Studio.ProjectItem.

如何循环浏览这些内容? WRITE 没有削减它,事实上我从一开始就猜测它不会......我只是想不通这是如何在 ObjectScript 中完成的:/

当你用w project.Items写的对象时,你得到这样的字符串2@%Library.RelationshiptObject,这个字符串可能有助于理解我们得到的对象是什么,在这种情况下它是[=18的对象=] %Library.RelationshiptObject,当你在documentation中打开这个class时,你可能会发现一些可以帮助你的方法。
Here 您可以找到一些示例,了解如何以对象方式和 sql.

处理关系
Set tKey = ""
For {
    ;tItem will be the first item in your list which will be ordered by OREF
    Set tItem = project.Items.GetNext(.tKey)
    Quit:(tKey = "")
    ;Do whatever you want with tItem
}