Improvements from PR feedback

This commit is contained in:
Scott Kyle 2016-06-09 13:07:05 -07:00
parent 3c657c3bbf
commit cdcb99a502
2 changed files with 10 additions and 16 deletions

View File

@ -56,6 +56,13 @@ function setupRealm(realm, realmId) {
});
}
function getObjectType(realm, type) {
if (typeof type == 'function') {
return objects.typeForConstructor(realm[keys.realm], type);
}
return type;
}
export default class Realm {
constructor(config) {
let schemas = typeof config == 'object' && config.schema;
@ -90,30 +97,18 @@ export default class Realm {
}
create(type, ...args) {
if (typeof type == 'function') {
type = objects.typeForConstructor(this[keys.realm], type);
}
let method = util.createMethod(objectTypes.REALM, 'create', true);
return method.apply(this, [type, ...args]);
return method.apply(this, [getObjectType(this, type), ...args]);
}
objects(type, ...args) {
if (typeof type == 'function') {
type = objects.typeForConstructor(this[keys.realm], type);
}
let method = util.createMethod(objectTypes.REALM, 'objects');
return method.apply(this, [type, ...args]);
return method.apply(this, [getObjectType(this, type), ...args]);
}
objectForPrimaryKey(type, ...args) {
if (typeof type == 'function') {
type = objects.typeForConstructor(this[keys.realm], type);
}
let method = util.createMethod(objectTypes.REALM, 'objectForPrimaryKey');
return method.apply(this, [type, ...args]);
return method.apply(this, [getObjectType(this, type), ...args]);
}
}

View File

@ -208,7 +208,6 @@ public:
return name;
}
// converts constructor object or type name to type name
static const ObjectSchema& validated_object_schema_for_value(ContextType ctx, const SharedRealm &realm, const ValueType &value) {
std::string object_type;