Skip to content
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

KeyPathArray does not support computed properties like backlinks #7131

Closed
cmelchior opened this issue Nov 14, 2023 · 2 comments
Closed

KeyPathArray does not support computed properties like backlinks #7131

cmelchior opened this issue Nov 14, 2023 · 2 comments
Assignees

Comments

@cmelchior
Copy link
Contributor

Currently, notifications will trigger on a child object when parent objects in a backlink property are modified, but it isn't an option to control the behavior using the optional KeyPathArray.

The reason seems to be that the KeyPathArray is defined as this:

using KeyPath = std::vector<std::pair<TableKey, ColKey>>;
using KeyPathArray = std::vector<KeyPath>;

And since backlinks are computed properties they do not have a ColKey, so it isn't possible to build up a KeyPath that involves a backlink.

I'm not sure there is an easy fix as this implementation seems pretty central to the notification system, but I might have missed it. As a minimum I suspect the public API needs to change to:

using KeyPath = std::vector<std::pair<TableKey, Property>>;
using KeyPathArray = std::vector<KeyPath>;

No users have requested this feature yet as far as I know, I just ran into this limitation while adding support and tests for it to the Kotlin SDK. For now we will just throw an exception if a keypath involving backlinks are used.

@tgoyne
Copy link
Member

tgoyne commented Nov 14, 2023

Backlinks have column keys which you can obtain from Table::get_opposite_column() on the forward link. https://github.com/realm/realm-swift/blob/master/Realm/RLMClassInfo.mm#L114 and https://github.com/realm/realm-swift/blob/master/Realm/RLMClassInfo.mm#L79 are the relevant parts of Cocoa's implementation of string -> KeyPath that supports backlinks.

@cmelchior
Copy link
Contributor Author

Ah cool. Closing this issue then as we will be adding that as part of #7087

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants