@alazier
I am unable to create a list of only string objects
This is how my model looks like
class ProductSummary extends Realm.Object {}
ProductSummary.schema = {
name: 'ProductSummary',
properties: {
productId:'string',
name:'string',
description:'string',
rating:'int',
comments:'int',
categories:{type:'list',objectType:'string'},
images:{type:'list',objectType:'string'},
price:{type:'Price'}
}};
This is how the response looks like
"productSummary": {
"links": [],
"productId": "PRD_1ola611nd0t",
"name": "Sample",
"description": "<p>Sample<br></p>",
"categories": [
"CAT_1rua60fnd0u"
],
"rating": 0,
"comments": 0,
"tags": [],
"image": "http://test.testsite.com/testProject/app-images/189_66164247/189_42527954.jpeg",
"price": {
"lowest": 100,
"highest": 100
}
}
In realm for android there is a way to wrap these types of primitive lists how could I do this using realm js
Error Message
`Target Type 'string' doesn't Exists for property 'categories'`
This is definitely something we hope to add. For now you have to create an object to wrap your primitive type:
let StringObjectSchema = {
name: 'StringObject',
properties: { value: 'string' }
};
class ProductSummary extends Realm.Object {}
ProductSummary.schema = {
name: 'ProductSummary',
properties: {
...
categories:{type:'list', objectType:'StringObject'},
images:{type:'list', objectType:'StringObject'},
...
}};
Its a bit annoying as when creating/accessing string objects you need to access/set the value property which might require some data transformation when importing or exporting data.
@alazier Thanks for the concern,
Now I get the following error JS value must be of type: object in the console
Full error log
Error: JS value must be of type: object
at sendRequest (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:79241:7)
at sendRequest (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:79256:8)
at Object.callMethod (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:79141:1370)
at Realm.<anonymous> (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:79047:771)
at realmdb_rnd.handleResponse (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:1564:18)
at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:1521:8
at tryCallOne (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:25182:8)
at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:25268:9
at JSTimersExecution.callbacks.(anonymous function) (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8497:13)
at Object.callTimer (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8329:1)
So before I do the db transaction I have to convert the String list into a key value pair. Where the the key being 'value'. For this to work , Or else it fails .
Do we have this possibility on version 1.0.2?
@eduardomoroni sorry no, this is still not implemented.
I think this feature is a must!
It's not practical to that trick and transform all the string list to {value: 'string} list
It's not making it easier.
Annoyingly so; for example
[1,2,3].map(num => {value: num}) // (3) [undefined, undefined, undefined]
Well, of course!
ProductSummary.schema = {
name: 'ProductSummary',
properties: {
...
categories:โstring[]โ,
images:"string[]",
...
}};
Is it right in React Native now?
Most helpful comment
I think this feature is a must!
It's not practical to that trick and transform all the
stringlist to{value: 'string}list