Comments (11)
Bidirectional relationships must be explicitly linked at this time. Here's an example:
@interface Item : RLMObject
@property Box *box;
@end
RLM_ARRAY_TYPE(Item);
@interface Box : RLMObject
@property RLMArray<Item> *items;
@end
...
Item *item = [[Item alloc] init];
Box *box = [[Box alloc] initWithObject:@[@[item]]];
item.box = box;
We have plans to simplify this pattern in the future.
from realm-swift.
Good to know, and this is the path that I already took. I was also trying to design a way to produce inverse relationship logic by incorporating preprocessor macros that would overload addObject, removeObject methods with the added functionality to set a value for the inverse property.
However the design of RLMArray holding it's own mutation methods makes this hard to do, as I can't add these mutation methods on the class itself.
Is there any design propositions within the realm team on how this will be simplified?
from realm-swift.
We are still at the early stages of discussion. The good news is that the functionality needed to support multi-directional relationships are already in the code base. It seems likely at this point that we will add a method to expose/fetch inverse relationship values without having to add an explicit property. This may put some limitations on what you can do (such as keypath queries on inverse relationships) but greatly simplifies the task of specifying multi-direction relationships on your models.
from realm-swift.
If I create a bidirectional relationship explicitly linked, as @jpsim mentions with the same example I get an error "Unknown type name 'Box'". Am I missing something? Thanks
from realm-swift.
You have to forward-declare the Box
type with @class Box;
from realm-swift.
What should I do when I have 3 objects related like this:
@interface Comment : RLMObject
@property NSNumber *createdTime;
@property NSString *text;
@property User *fromUser;
@property Media *fromMedia;
@end
RLM_ARRAY_TYPE(Comment)
@interface Media : RLMObject
@property NSNumber *created_time;
@property NSString *standard_relutionURL;
@property RLMArray<Comment> *comments;
@property Comment *caption;
@property User *fromUser;
@end
RLM_ARRAY_TYPE(Media)
@interface User : RLMObject
@property NSString *full_name;
@property NSString *profile_pictureURL;
@property NSString *username;
@property RLMArray<Media> *medias;
@property RLMArray<Comment> *comments;
@end
RLM_ARRAY_TYPE(User)
If I forward-declare User
type with @class User;
I still get Unknown type for Media in the interface of Comment.
from realm-swift.
Forward declare Media
as well.
from realm-swift.
Has there been any progress on this? Doing this with remote JSON data is very tedious
from realm-swift.
+1
from realm-swift.
We have had a few discussions on the design for this. Ideally we would like to provide the ability to declare a property as an the inverse of a property on another model. Unfortunately this would imply full query support which is a fairly large task and will take a long time to make work properly.
In the shorter term it would be possible to at least expose object and array property backlink information which is already stored internally in Realm. If we exposed this it would most likely be a method on RLMObject
which returns all other objects which link to it (either using an RLMObject or RLMArray property). This is probably something that we could make work pretty quickly if it would be useful.
from realm-swift.
This would be very handy. It would be absolutely sufficient for all my current needs.
from realm-swift.
Related Issues (20)
- please_report_this_issue_in_github_realm_realm_core_v_13_23_1
- [Duplicate] Importing RealmSwift within Xcode 15 causes Documentation Builds to fail.
- Inquiry: Support for Universal Binary (Intel and Apple Silicon) HOT 1
- Using RealmSwift via SPM in an Xcode Playground has been broken since v10.41.0
- Will it support Xcode15.1 HOT 1
- Crash while trying to get scheme version HOT 3
- App crashes when trying to init Realm HOT 3
- Failed to open file at path: Operation not permitted HOT 14
- We are unable to fetch the lib in carthage HOT 5
- Crash realm::util::File::sync()
- Unexpected error type passed to sync error handler HOT 2
- Crashed: com.apple.root.background-qos
- Migration from old version to latest version HOT 5
- No such module 'RealmSwift' - Error on Sonoma (14.2.1) - Xcode 15.1 HOT 4
- Crash in Combine.swift
- Sort results is different between realm sort and Swift sort HOT 2
- The persisted primary key is not working as expected HOT 3
- Invalid column key RLMException HOT 7
- Add initial support for geospatial queries on points.
- Add support for collections in mixed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-swift.