I am trying to open a new Realm db file using realm-cpp sdk with the following schema that includes nested objects
struct Card : realm::object<Card> {
realm::persisted<realm::object_id> _id{realm::object_id::generate()};
realm::persisted<std::string> name;
realm::persisted<std::string> question;
realm::persisted<std::vector<std::string>> options;
static constexpr auto schema =
realm::schema("Card",
realm::property<&Card::_id, true>("_id"),
realm::property<&Card::name>("name"),
realm::property<&Card::question>("question"),
realm::property<&Card::options>("options")
);
};
struct Deck : realm::object<Deck> {
realm::persisted<realm::object_id> _id{realm::object_id::generate()};
realm::persisted<std::string> name;
realm::persisted<std::vector<Card>> cards;
static constexpr auto schema =
realm::schema("Deck",
realm::property<&Deck::_id, true>("_id"),
realm::property<&Deck::name>("name"),
realm::property<&Deck::cards>("cards")
);
};
auto realm = realm::open<Deck>({dbFile});
If I remove the nested property realm::persisted<std::vector<Card>> cards
, everything works as expected. But when I add the nested object, it gives runtime exception:
DB: 30017 Thread 0x108a6c580: Open file: ./test.db/realm.db
libc++abi: terminating with uncaught exception of type realm::SchemaValidationException: Schema validation failed due to the following errors:
- Property 'Deck.cards' of type 'array' has unknown object type 'Card'
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
Could you suggest what could be wrong with my db schema?
Versions:
- realm-cpp sdk alpha
- cmake 3.18.1
- macOS Monterey 12.6.5
- Apple clang version 14.0.0 (clang-1400.0.29.202). Target: arm64-apple-darwin21.6.0.