Hi,
I need to save questions and responses for multiple customers that are customer defined (questions) onto the users device. I will not know them ahead of time as I will fetch from an API. The problem is I don’t know how to store the users responses as depending on the question/component I render it could be a date, string, int or an array of strings. I was using “mixed” up until I had to create a multi select component and realised that mixed does not allow the storage of arrays.
I have outlined below a basic object I need to store and my current model.
Any help would be much appreciated!!!
Thank you.
(Using Expo with @realm & @realm/react)
const stateObject = {
id: "A123",
number: "ABC123ZZL",
userName: "Joe Bloggs",
userId: "JoeBloggs190Z",
created: 2023-12-05T15:30:30.711Z,
responses: [
{question: "Are you happy", userResponse: "Yes", _id: "uuid"},
{question: "Provide details", userResponse: "This is dummy data.", _id: "uuid"},
{question: "What is your favourite number?", userResponse: 53, _id: "uuid"},
{question: "When is your birthday?", userResponse: 2023-12-05T15:30:30.711Z, _id: "uuid"},
{question: "Select your favourite colours?", userResponse: ["green", "blue", "yellow"], _id: "uuid"},
{question: "Signature", userResponse: base64_string, _id: "uuid"},
]
};
export class UserResponses extends Realm.Object {
id
number
userName
userId
responses
created
static primaryKey = "id";
static schema = {
name: 'UserResponses',
primaryKey: "id",
properties: {
id: 'string',
number: 'string',
userName: 'string',
userId: 'string',
responses: {
type: 'list',
objectType: 'Response',
},
created: 'date'
}
}
}
export class Response extends Realm.Object {
_id
question
userResponse
static primaryKey = "_id";
static schema = {
name: 'Response',
primaryKey: "_id",
properties: {
_id: 'string',
question: 'string',
userResponse: 'mixed'
}
}
}