Doubt/Issue creating new instances using model with accountRelation "set"

I am using Ceramic One, and created a model with accountRelation “set”, where I am setting two fields as it can be seen in the following code providing the model:

const DeploymentIndexModel: ModelDefinition = {
    version: "2.0",
    name: "DeploymentIndex development",
    description: "A unique anchor document for a specific application deployment development",
    // This model is controlled by an admin/system DID. 
    // Each deployment is a unique instance.
    accountRelation: { type: "set", fields: ["environment", "deployment_version"] }, 
    interface: false,
    implements: [],
    schema: {
      type: "object",
      properties: {
        // Human-readable name for the deployment
        environment: { type: "string" },
        // Optional version for this deployment
        deployment_version: { type: "string" },
      },
      required: ["environment", "deployment_version"],
      additionalProperties: false,
    },
  };

The thing is that, when I try to create different instances of this model under the same authenticateDID, I think I should receive the same StreamID, but I am getting different ones. Is this right?

For example in the following code, I should get the same streamIDs, right? Correct me if I am wrong:


const devDeploymentInstance = await modelInstanceClient.createInstance({
    model: deploymentIdModelStreamId,
    controller: authenticatedDID,
    content: {
        environment: "devDeploymentTest",
        deployment_version: "v_",
      },
    shouldIndex: true,
});

const devDeploymentInstance2 = await modelInstanceClient.createInstance({
  model: deploymentIdModelStreamId,
  controller: authenticatedDID,
  content: {
      environment: "devDeploymentTest",
      deployment_version: "v_",
    },
  shouldIndex: true,
});

await new Promise(resolve => setTimeout(resolve, 3000));


// To be used in 
console.log("instance stream", devDeploymentInstance.baseID.toString()); 
console.log("instance 2 stream", devDeploymentInstance2.baseID.toString());

Thanks a lot! @mohsin

Also, another thing that i realize is that when I create an instance using accountRelation “set”, I am not able to get the document state (getDocumentState) from the instance, while using “list” works for me. Not sure if I am doing something wrong.

That’s a great question. By default, ModelInstanceClient.createInstance will create a unique stream, even if the content across two SDK calls is the same.

There is a way to create what are called deterministic streams where you can get the same stream ID each time. Let me check and get back to you.

1 Like

Also, you’re right… ModelInstanceClient.getDocumentState doesn’t seem to be working for new MIDs with accountRelation “set”.

I’m checking.

1 Like

Perfect! Thanks a lot @mohsin, let me know when you figure out or when fixed to use it as it would be useful for my use case.

@mohsin I think I just realized about this error. “set” account relation actually works, the problem here is that I was using a model with “set” account relation and to create instances I was using createInstance method, which is wrong, because “single” and “set” account relation models should use createSingleton method instead.

If I use it this way, it works as expected. Correct me if I am wrong, but I think I am right.

Thanks a lot!

Forget previous message, still having the issue, but it is true that i was not using it properly.

1 Like

Ok, understood. I’ll keep investigating and keep you posted.

1 Like