-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
<!---
Questions: If you have questions about HOW TO use Realm, please ask on
StackOverflow: http://stackoverflow.com/questions/ask?tags=realm
We monitor the realm tag.
Feature Request: Just fill in the first two sections below.
Bugs: To help you as fast as possible with an issue please describe your issue
and the steps you have taken to reproduce it in as much detail as possible.
-->
Goals
<!--- What are you trying to achieve? -->
Hi, my goal is to use ES6 Classes and inheritance as Realm models.
This possibly relates to https://github.com/realm/realm-js/issues/2768
After upgrading realm and react-native from
"realm": "2.23.0", "react": "16.0.0", "react-native": "0.50.3",
the following error shows up
Realm object constructor must not return another value
I was wondering if there is any way to get this to work with later versions
https://github.com/realm/realm-js/issues/2768#issuecomment-604438625 This mentions that we shouldn't extend Realm.Object but doesn't say anything else about extending other classes.
https://realm.io/docs/javascript/latest/#classes The docs don't mention anything about this either.
Code Sample
class BaseModel {} export class Account extends BaseModel { static schema = { name: 'Account', primaryKey: 'uuid', properties: { uuid: 'string', id: {type: 'int', indexed: true}, firstName: 'string', lastName: 'string', username: 'string', apiKey: 'string', lastLogin: 'date' }, }; } database = new Realm({ path: 'core.realm', schema: [ Account, // eslint-disable-line no-use-before-define // ... ], schemaVersion: 13, migration: () => null, });
Similar to https://github.com/realm/realm-js/issues/2768 the error goes away when removing the extends
Version of Realm and Tooling
"realm": "^3.6.5", "react": "^16.13.1", "react-native": "0.62.0", node v10.14.2 macOS Catalina 10.15.4
I also tried 5.0.2 and 4.0.0-beta.2 and got the same error