使用已存在的数据进行Magical Record导入 [英] Magical Record import with already existing data

查看:131
本文介绍了使用已存在的数据进行Magical Record导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 Magical Record 将数据导入我的 CoreData db。

I'm trying to use Magical Record to import data into my CoreData db.

我目前正在处理实体 Person

firstName lastName personID 属性。 (我知道我不需要idString,我不是在内部使用它,它用于回到服务器)。

A Person has firstName, lastName, personID attributes. (I know I don't need the idString, I'm not using it internally, it is used to talk back to the server).

无论如何,如果我已经有人...

Anyway, if I already have the person...

firstName - John
lastName - Smith
personID - 1

我下载了JSON ...

And I download the JSON...

[
    {
        firstName: John,
        lastName: Doe,
        id: 1
    },
    {
        firstName: Michael,
        lastName: Caine,
        id: 2
    },
    {
        firstName: Angelina,
        lastName: Jolie,
        id: 3
    }
]

添加 Michael Angelina 并将 John Smith 更新为 John Doe ,因为它已经存在与相同的id vs personID。

I'd want the import to add Michael and Angelina and to update John Smith to John Doe because it already exists with the same id vs personID.

我设置mappedKeyName id和personID。

I've set the mappedKeyName between id and personID.

是否可以这样做?我一直在阅读此博客... http://www.cimgf.com / 2012/05/29 / importing-data-made-easy / 关于键名的自动映射等...并想知道我是否可以利用这个来做我想要的。

Is it possible to do this? I've been reading this blog... http://www.cimgf.com/2012/05/29/importing-data-made-easy/ about automatic mapping of key names etc... and wondered if I could exploit this to do what I want?

我已经从博客中读过关于relatedByAttribute的部分,但我不知道应该在哪里设置它和什么?

I have read the part about relatedByAttribute from the blog but I'm not sure where I should be setting it and what to?

设置它的实体Person?还是属性personID?我应该怎么设置呢? ID?

Should I set it on the entity Person? Or the attribute personID? And what should I set it to? "id"? Or something else?

推荐答案

我不确定您是否在核心数据的userInfo区域中使用relatedByAttribute设置模型。你在这里没有提到你的问题。我建议你仔细检查一下。并澄清,它被称为relatedByAttribute,因为你放到值部分的字符串是CoreData属性,它涉及实体,没有json(或其他对象)数据。所以,检查这两件事,如果仍有问题,请在github上打开一张票,最好用单元测试来帮助描述问题。

I'm not sure if you're using the relatedByAttribute setting in the userInfo area of your Core Data model. You don't mention that in your issue here. I suggest you double check that. And to clarify, it's called relatedByAttribute because the string you put into the value section is the CoreData attribute which relates the entities, no the json (or other object) data. So, check those two things and if there still a problem, please open a ticket on github, preferably with a unit test that helps describe the problem.

这篇关于使用已存在的数据进行Magical Record导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆