mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-10 14:25:58 +00:00
Make it possible to assign a List or Results to a List property once more (#1126)
* Make it possible to assign a List or Results to a List property. The change made in #1069 to improve error messages when values of incorrect types were assigned to a given property was being too narrow in the types it accepted for list properties, allowing only arrays. Lists and Results are now accepted once more. * Update CHANGELOG.md
This commit is contained in:
parent
db7284ee97
commit
89149c0a75
@ -8,7 +8,7 @@ vNext Release notes (TBD)
|
||||
* Add support for retrieving user account information.
|
||||
|
||||
### Bug fixes
|
||||
* Node
|
||||
* Fix regression where setting a Results or List object to a `list` property would throw.
|
||||
|
||||
1.8.3 Release notes (2017-6-27)
|
||||
=============================================================
|
||||
|
@ -39,6 +39,11 @@
|
||||
namespace realm {
|
||||
namespace js {
|
||||
|
||||
template<typename>
|
||||
struct ResultsClass;
|
||||
template<typename>
|
||||
struct ListClass;
|
||||
|
||||
enum PropertyAttributes : unsigned {
|
||||
None = 0,
|
||||
ReadOnly = 1 << 0,
|
||||
@ -369,7 +374,17 @@ inline bool Value<T>::is_valid_for_property(ContextType context, const ValueType
|
||||
return true;
|
||||
case PropertyType::Array:
|
||||
// FIXME: Do we need to validate the types of the contained objects?
|
||||
return is_array(context, value);
|
||||
if (is_array(context, value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_object(context, value)) {
|
||||
auto object = to_object(context, value);
|
||||
return Object<T>::template is_instance<ResultsClass<T>>(context, object)
|
||||
|| Object<T>::template is_instance<ListClass<T>>(context, object);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
case PropertyType::Any:
|
||||
case PropertyType::LinkingObjects:
|
||||
|
@ -921,5 +921,16 @@ module.exports = {
|
||||
var p1 = realm.create('PersonObject', { name: 'Ari', age: 'Ten' });
|
||||
});
|
||||
}, new Error("PersonObject.age must be of type: number"));
|
||||
},
|
||||
|
||||
testValidTypesForListProperties: function() {
|
||||
var realm = new Realm({schema: [schemas.PersonObject]});
|
||||
realm.write(function () {
|
||||
var p1 = realm.create('PersonObject', { name: 'Ari', age: 10 });
|
||||
var p2 = realm.create('PersonObject', { name: 'Harold', age: 55, children: realm.objects('PersonObject').filtered('age < 15') });
|
||||
TestCase.assertEqual(p2.children.length, 1);
|
||||
var p3 = realm.create('PersonObject', { name: 'Wendy', age: 52, children: p2.children });
|
||||
TestCase.assertEqual(p3.children.length, 1);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user