Code Monkey home page Code Monkey logo

Comments (11)

jpsim avatar jpsim commented on May 22, 2024

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.

carlossless avatar carlossless commented on May 22, 2024

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.

alazier avatar alazier commented on May 22, 2024

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.

ortizroberto avatar ortizroberto commented on May 22, 2024

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.

tgoyne avatar tgoyne commented on May 22, 2024

You have to forward-declare the Box type with @class Box;

from realm-swift.

ortizroberto avatar ortizroberto commented on May 22, 2024

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.

tgoyne avatar tgoyne commented on May 22, 2024

Forward declare Media as well.

from realm-swift.

eni9889 avatar eni9889 commented on May 22, 2024

Has there been any progress on this? Doing this with remote JSON data is very tedious

from realm-swift.

zvonicek avatar zvonicek commented on May 22, 2024

+1

from realm-swift.

alazier avatar alazier commented on May 22, 2024

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.

zvonicek avatar zvonicek commented on May 22, 2024

This would be very handy. It would be absolutely sufficient for all my current needs.

from realm-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.