-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Realm.Object property type #3938
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Feel free to merge as soon as the tests are green.
tests/js/object-tests.js
Outdated
|
||
testGetPropertyType: function () { | ||
const realm = new Realm({ | ||
schema: [schemas.AllTypes, schemas.TestObject, schemas.LinkToAllTypes], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh actually: I would love to see a test using a property of type mixed
as well. To verify that it's the underlying type and not simply the type from the schema which gets returned.
This also needs an updated changelog.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
src/js_realm_object.hpp
Outdated
throw std::invalid_argument(util::format("No such property: %1", property_name)); | ||
} | ||
|
||
return_value.set(prop->type_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get the JavaScript names, you need to call TypeErrorException::type_string(prop)
(https://github.com/realm/realm-js/blob/master/src/js_realm.cpp#L78).
If prop->type_string() == "mixed"
, you need to unwrap the property. It is something like:
auto obj = realm_object->obj();
DataType typ = obj.get().get_type();
// convert typ to string
794a028
to
f9fb1dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
What, How & Why?
Since all numeric types (int, long, double) are represented as a
number
when read from our SDK, it makes sense to implement a method to get the underlying type of the property value, if your application (such as MongoDB Realm Studio) cares about this. Throws an exception if a property with the given name does not exist.E.g.
This closes #3646
☑️ ToDos
[ ] 📝Compatibility
label is updated or copied from previous entry[ ] 💥Breaking
label has been applied or is not necessaryIf this PR adds or changes public API's: