Creating a nested array of objects from a sample schema

Is it possible to create a schema that includes in its definition a relationship to another schema? In other words, in this field on schema 1, load an array of json objects based on schema 2.

In my case I would like to create an API request that includes an array of objects based on my second schema, so to speak.

Best
Fran.

Yes you can, using the new APIs feature. For example, you can create an API with the following handler script:

# Generate 10 users
schema "Users"
users = generate 10

# switch to the Groups schema
schema "Groups"
users.each do |user|
  user['blood_group'] = generate 1 # generate one group for each
end

users # return users as the result

This is pretty awesome. Thank you!

This worked great. I am running into a small issue though.

page["banner"] = generate 1
page["banner"]["category"] = set "category[2]", values: ["banner", "home"]

Expected

"category": [
   "banner",
   "home"
]

Actual

"category": {
    "values": [
        "banner",
        "home"
    ]
}

What am I doing wrong?

I figured it out. (Why does this always happen 2 seconds after finally giving up?)

page["banner"] = generate 1
page["banner"]["category"] = ["banner", "home"]

Actually, I think my issue persists, but in a different way from what I imagined. How do I set field parameters?

Using the following: set "body", min: 1, max: 1 on different lines, without result.

#homepage
schema "page"
page = generate 1

# generate from ContentItem
schema "ContentItem"

# accountActions using ContentItem Schema
--> attempted here (see results 1)
page["accountActions"] = generate 3
page["accountActions"].each do |action|
--> attempted here (see result 2)
--> even attempted: action["body"] = set "body", min: 1, max: 1 (see result 2)
  action["category"] = ["accountActions","home"]
  action["imageUrl"] = "user"
  action["imageType"] = "SvgUse"
end

#return the response
page

### END API SCRIPT

### OUTPUT

# result 1: paragraph length follows schema settings, not "set" instructions.

# result 2
"body": {
    "min": "1",
    "max": "1"
}

Edited for clarity.