Hydrating Object Relationships with RKObjectMapping without coredata

107 views
Skip to first unread message

Bill Brigden

unread,
Feb 11, 2013, 12:47:02 PM2/11/13
to res...@googlegroups.com
Hi all,

I've started using Restkit - really impressed so far though have hit a bit of a stumbling block.. If I want to have an entity that references another entity via a foreign key like this:


    message =     {
        51192bac2c3e998937000002 =         {
            "_id" = 51192bac2c3e998937000003;
            "expiry_ts" = 1360607676;
            "message" = "123123123";
            "rx_uid" = 51192a962c3e998f37000002;
            "tx_uid" = 511383a62c3e999b1c000001;
        };
    };
    users =     {
        511383a62c3e999b1c000001 =         {
            email = "te...@test2.com";
        };
        51192a962c3e998f37000002 =         {
            email = "te...@test.com";
        };
    };

--------------------------

Is this something that is possible when not using Coredata to have managed objects? I've looked at using normal mapping with a property mapping  of the tx_uid => the users primary key however haven't managed to get it to work..

I don't want to post more code here as it may confuse the situation.. I'm after proper relationship mapping to the two entities Message and User with message having the nested users inside... If someone could advise if its possible / a rough idea of how it would be achieved that would be great.

Thanks in advance 

Blake Watters

unread,
Feb 12, 2013, 10:04:10 PM2/12/13
to res...@googlegroups.com
There's not currently any support for connecting objects in this fashion without using Core Data. With non-managed objects, everything is held in memory on the object graph being mapped -- there's no store of record to do any lookup on and then you'd have to implement querying. If you need these kind of referential connections, you are probably better off just using Core Data. If your data is transient, you can just use an in-memory store instead of SQLite to keep the objects transient.

Note that you could implement ths with non-managed objects by rolling your own implementation of the `RKMappingOperationDataSource` protocol (see http://restkit.org/api/0.20.0-pre5/Protocols/RKMappingOperationDataSource.html), but it will require you to handle storing the objects, querying them, and purging the memory as appropriate.


--
You received this message because you are subscribed to the Google Groups "RestKit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to restkit+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

john....@mindsea.com

unread,
May 23, 2013, 8:49:00 AM5/23/13
to res...@googlegroups.com
Hi Blake,

I'm trying to accomplish what you describe in your last paragraph, but running into a roadblock trying to figure out how to get RestKit to actually use my own RKMappingOperationDataSource implementation. A few different objects use it, but they are all given either a RKObjectMappingOperationDataSource or RKManagedObjectMappingOperationDataSource instance created inside RestKit. I'm looking for a way to tell RestKit "here's my RKMappingOperationDataSource instance, please use it where necessary" but am not finding it.

Any help would be appreciated! If that hook is not in there yet, I would be happy to add it, since I need it for this project.

Thanks,
John

Blake Watters

unread,
Jun 8, 2013, 6:10:19 PM6/8/13
to res...@googlegroups.com
Yeah there's not currently a hook for overriding the data source in this way. I am guessing that you really need to hook into `RKObjectResponseMapperOperation` or `RKManagedObjectResponseMapperOperation`. I could definitely see adding a class accessor for registering an alternative data source class.

Please open up a Github issue if you'd like to get this feature in and I'll be happy to whip up an API sketch for you if you want to implement it.
Reply all
Reply to author
Forward
0 new messages