- How do i define if a particular field can be array of one or more schema types ( for example - You have a person schema where pets field could be array of cats ( cats ) or array of dogs ( dogs ) . From what I learnt earlier there was type “Union” to specify it can hold schema of different types and now union throws error .
- Should embedded objects also be part of realm config schema ?
In Realm, you will be using a list data type. It behaves very similar to an array and in fact list
maps to the JavaScript Array type. You can also specify that a field contains a list of primitive value type by appending []
to the type name.
You should also investigate the mixed
property type - it can hold different data types.
Clicking through the above links will likely answer your question more effectively and completely than an answer here.
Embedded objects are managed and part of an objects schema. But realm config schema is a bit vague. Can you claify what you’re asking, perhaps provide a use case?
Ahhh! I use list data type to specify array . From what i see [mixed] data type doesn’t serve my purpose . I’m looking to achieve something like this - type union with different data types
(https://www.mongodb.com/docs/realm/sdk/react-native/realm-database/schemas/mixed/)
Are you asking about
info: {type: 'union', objectTypes: [ 'string', 'int', 'Person']
If so, isn’t that just a List of more mixed types?
(in the future, please post code as text and use the formatting </> feature, and not screen shots)
(post deleted by author)
(post deleted by author)
(post deleted by author)
I’m looking to implement something like this - schema type - list , object type - Object . For reference the ‘children’ field in below code
export class HubSection extends Realm.Object {
static schema = {
name: 'hubSection',
properties: {
id:'objectId',
title: 'string',
entityType: 'string',
layoutStyle: 'string',
cardStyle: 'string',
showFilter: 'bool',
userDefined: 'bool',
children: 'mixed[]',
// children: { type: "list", objectType: "mixed" },
},
};
}
Note: And , this line of code throws error 'children: { type: "list", objectType: "mixed" } ' . But this is supported by docs here [https://github.com/realm/realm-js/issues/3389](https://github.com/realm/realm-js/issues/3389)