martijnwalraven / meteor-ios

Meteor iOS integrates native iOS apps with the Meteor platform (http://www.meteor.com) through DDP
MIT License
740 stars 79 forks source link

How to map embedded data from Meteor responce? #51

Open Avtolic opened 9 years ago

Avtolic commented 9 years ago

Hello

Could someone please tell me how should be CoreData model designed to work correctly with the following Meteor responses:

{
    collection = users;
    fields =     {
        profile =         {
            accountType = student;
            birthday = "<null>";
            firstName = YuryTestStudent3;
            fullName = YuryTestStudent3;
            lastName = "";
            level = 1;
            parentId = R72enQ6CMus7w95gn;
            teacherId = ggGggDkQvQYFqzojT;
        };
        username = "@child_R72enQ6CMus7w95gn_06327e8c-1def-4e0c-ba1e-019666ff969f";
    };
    id = MMn5PeQiTyoPgM7KF;
    msg = added;
}

As you can see some data is not directly inside fields but is in profile. How this response should be mapped? Should I create a separate profile table? Or should mapping logic be changed? meteor-ios lib is great but quite complex so if anyone could help me or show the right direction it will be great.

Thank you

martijnwalraven commented 9 years ago

The best way to support embedded value objects like this is through a 'transformable' mapping to a dictionary in Core Data. The Todos example has a mapping for 'profile' set up as part of User.

LinkXXI commented 9 years ago

Is it possible to add support for mapping embedded data?

I have a situation currently where I'd like to use a predicate to filter on some embedded data (it's probably bad design but I can't change it at this point).

Being able to map an embedded property using fieldName pofile.accountType in the User Info section of the data model.

calioasis commented 8 years ago

@LinkXXI You can still filter on embedded data. Just create a derived variable for whatever you want to access. Since this library doesn't use SQLite as a backing store, you can run a query against anything