Hi,
I have an issue with the error messages. I am getting the following error:
Error: 'Property' must be of type: string
I obviously have a problem with my data but I have no clue _which_ property is being provided the wrong data. Is there anyway the message could be updated to indicate where the problem lies? Or, if I'm just being dumb, point me to where I can see what property is having issues.
Thanks,
Sam
After allot of trial and error this error seems to be if the primary key property is missing on a newly created object. So, I guess it'd be good if the error message said that.
These types of errors are a pain to debug, we really need better error reporting for this, this ends up taking so much time to track down (removing items one at a time) - a simple message like "Property 'date' must be of type: date" would be so useful and save so much time, even trying to track down the error with the debugger is difficult due to how the objects are structured.
Looks like we just have to deal with this for now, if you're having this issue, you'll have to go through one at a time to each of your props and check it manually, this goes for nested objects also.
This is definitely something we want/need to improve. Thanks for the feedback.
@kristiandupont I've noticed this same error on 1.0.0. It happened when a property of mine was not optional and I was trying to create it with a null value.
properties: {
...
email: { type: 'string' },
}
realm.create('FeedItem', {
...
email: null,
});
@rdougan yes, this is covered by #787. Sorry for the inconvenience, I hope we will get it fixed soon.
@rdougan @kristiandupont How did you fix the null issue. Same issue I am getting. Here I am getting data from the API in react native which I have to just save it in realm db. In API some values are null because of which i am getting [Error: CompanyUser.deputed_to_name must be of type 'string', got 'null' (null)]
the same issue hey @yuvaraj119 did you get a solution
the same issue hey @yuvaraj119 did you get a solution
1803 is solved
the same issue hey @yuvaraj119 did you get a solution
Yes I fixed by removing null values in API response and then I insert an empty string.
which means I remove that key from the api response which has null values.
This will remove the null,empty keys from the response object or array of api
export const filterResponse = (obj) => {
for (var key in obj) {
if (obj[key] === '' || obj[key] === null || obj[key] === undefined) {
delete obj[key];
} else if (Object.prototype.toString.call(obj[key]) === '[object Object]') {
filterResponse(obj[key]);
} else if (Array.isArray(obj[key])) {
console.log("hello" + obj[key]);
if (obj[key].length === 0) {
delete obj[key];
} else {
for (var _key in obj[key]) {
filterResponse(obj[key][_key]);
}
obj[key] = obj[key].filter(function (v) { return v !== undefined; });
if (obj[key].length === 0) {
delete obj[key];
}
}
}
}
return obj;
}
the same issue hey @yuvaraj119 did you get a solution
Yes I fixed by removing null values in API response and then I insert an empty string.
which means I remove that key from the api response which has null values.
This will remove the null,empty keys from the response object or array of apiexport const filterResponse = (obj) => {
for (var key in obj) {
if (obj[key] === '' || obj[key] === null || obj[key] === undefined) {
delete obj[key];
} else if (Object.prototype.toString.call(obj[key]) === '[object Object]') {
filterResponse(obj[key]);
} else if (Array.isArray(obj[key])) {
console.log("hello" + obj[key]);
if (obj[key].length === 0) {
delete obj[key];
} else {
for (var _key in obj[key]) {
filterResponse(obj[key][_key]);
}
obj[key] = obj[key].filter(function (v) { return v !== undefined; });
if (obj[key].length === 0) {
delete obj[key];
}
}
}
}
return obj;
}
Your solution methods is good 锛宐ut your can also try this
路路路
properties: {
title: 'string?',
sub_title: 'string?',
img_url: 'string?',
}
路路路路
Most helpful comment
This is definitely something we want/need to improve. Thanks for the feedback.