-
Notifications
You must be signed in to change notification settings - Fork 585
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
Not nullable object relationship #6195
Comments
@petmongrels Links will always be nullable. In version 12.0.0 we have tied up the schema validation so it will mislead you. Prior to version 12.0.0, our schema validation wasn't strict. If line 9 in your schema was interpreted strictly, line 33 would fail as In Realm, a link is a many-to-one relationship. It can be that embedded objects is a better match for your data model. |
Yes we want it to fail but it doesn't. |
Unfortunately it is not possible to specify that a link must be required (strictly speaking, Realm supports N:0 relationships, and not N:1 relationships). If it was possible, you could easily end in the situation where deleting an object was not possible. For example consider the following case: const commentA = {
uuid: "fooA",
};
const commentB = {
uuid: "fooB",
};
const individual = {
uuid: "bar",
name: "footer",
};
realm.write(() => {
const individual = realm.create("Individual", { uuid: "bar", name: "foobar", });
realm.create("Comment", { uuid: "A", subject: individual });
realm.create("Comment", { uuid: "B", subject: individual });
});
realm.write(() => {
realm.delete(realm.objectByPrimaryKey("Individual", "foo"));
// both Comment objects have property subject set to null --> if required, we cannot allow delete() on the Individual object
}); I believe it is similar to a foreign key in SQL. |
Thank for your reply. Understood that the support is not there. But the requirement is quite common. Individual/Comment is not the best example because both can be understood to be transactional data. We could have Individuals with relationship lets says a Country. There are multiple individuals in a country or province (they can have their own lifecycle like change in name of province etc). Business-wise you never delete country in your application, only Individuals. Hibernate/Spring-JPA support this for very long time and realm should also consider providing support for it. |
@petmongrels Thank for the detailed suggestion. I will put the issue on our backlog and discuss "hot topics in data modelling" with a broader audience (aka the other SDK teams). |
How frequently does the bug occur?
Always
Description
I have two objects comment and individual. Comment is linked to individual. We want to make the relationship from comment to individual not nullable but it is not taking effect.
Please see the code here.
https://github.com/avniproject/avni-client/blob/85ee69f3b9da94ba4dce5d0d249f878f6ccbac3a/packages/openchs-android/integrationTest/RealmIssuesApp.js
versions
"react-native": "0.72.3",
"realm": "11.8.0",
Stacktrace & log output
Can you reproduce the bug?
Always
Reproduction Steps
I have the above component as a part of RN app.
Version
11.8.0
What services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
Android 11 API 30 Genymotion
Build environment
Which debugger for React Native: ..
NA
Cocoapods version
No response
The text was updated successfully, but these errors were encountered: