-
Notifications
You must be signed in to change notification settings - Fork 95
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
Cannot include a Realm class into another Realm class #1824
Comments
Use |
Regarding embedded types, ChatGPT is wrong, the correct annotation is |
Realm doesn't support enums natively, so you will need to map them to either a string or an int. Something like: import 'package:realm/realm.dart';
part 'main.realm.dart';
@RealmModel()
class _Car {
@MapTo("type")
late String _type;
CustomType get type => CustomType.values.byName(_type);
set type(final CustomType value) => _type = value.name;
}
enum CustomType { enabled, disabled }
final realm = Realm(Configuration.local([Car.schema]));
void main() {
realm.write(() {
// best bet right now ..
realm.add(Car(CustomType.enabled.name));
// or
realm.add(Car('')..type = CustomType.enabled);
});
} |
As you seem to be a new user, I should probably end this by pointing out that all the Atlas Device Sync (aka Realm) SDKs are deprecated. |
i guess declaring that on the doc may make users easier to understand. |
What happened?
I wonder how to include custom objects on Realm class which I could found nowhere on the doc.
Repro steps
The codes above runs with no error. Then I tried
Now it complains
List<CustomField> is not a realm model type
. Even withoutList
the issue exists.ChatGPT told me to add a label
@RealmEmbedded
but it doesn't seem to work. Dart language server complainsUndefined name 'RealmEmbedded' used as an annotation. Try defining the name or importing it from another library.
The script complainsCould not resolve annotation for 'class _CustomField'.
What's more: What would it happen if I try to use an abstract class object as a data field of a Realm object? How to express things like Rust enums or C/C++ unions?
Version
Dart 3.5.1 Flutter 3.24.1
What Atlas Services are you using?
Local Database only
What type of application is this?
Flutter Application
Client OS and version
Windows 11 21H2
Code snippets
No response
Stacktrace of the exception/crash you're getting
Relevant log output
The text was updated successfully, but these errors were encountered: