Hey Ceramic team!
I am trying to build a dApp where I need an account-to-account relation for the “follow user” functionality.
This is my model:
type Follow @ createModel(accountRelation: LIST, description: "Follow details"){
follower: DID! @ documentAccount
following: DID! @ accountReference
}
While I am able to query based on the follower field, I want to query based on the following field as well. I referred to this example
tejaswinigurumoorthy:
Model to Account
Model-to-account relations enable you to link data to and query data from an account other than the data’s author. When using this type of relation, you need to define a model field that stores an account (e.g. a DID), then add the @accountReference directive to make it queryable.
Example: Direct message (DM)
Here’s a model for a user-to-user message that can be queried based on the recipient:
Define message model
Relate it to author’s account
Allow unlimited sent messages
Store reference to recipient’s account
Enable queries based on recipient
type Message @ createModel(accountRelation: LIST, description: “Direct message model”) {
recipient: DID! @ accountReference
directMessage: String! @string (minLength: 1, maxLength: 200)
}
Where:
accountRelation relates the message to the author’s account
LIST allows unlimited messages
recipient references the recipient’s account by storing its DID!, using @ accountReference
How to query based on @ accountReference?
Link- https://composedb.js.org/docs/0.4.x/guides/data-modeling/relations#model-to-account
How to query based on @ accountReference?
mzk
July 24, 2023, 7:20pm
2
Hello @tejaswinigurumoorthy !
Thanks for sharing the context above.
Before jumping in, I’d like to first point out this RFC (and corresponding development work currently underway) that might be a helpful reference to the current state and future plan for querying/filtering/ordering by subfield.
As you mentioned, you can currently load lists of documents based on their controlling account. Are you looking for a way to mirror the same behavior for the following field? Basically the equivalent of a SQL WHERE clause on the recipient field?