{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/2644","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2644/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2644/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2644/events","html_url":"https://github.com/realm/realm-cocoa/issues/2644","id":110118832,"number":2644,"title":"Support partial updates when using `add` API","user":{"login":"jakecraige","id":3799709,"avatar_url":"https://avatars.githubusercontent.com/u/3799709?v=3","gravatar_id":"","url":"https://api.github.com/users/jakecraige","html_url":"https://github.com/jakecraige","followers_url":"https://api.github.com/users/jakecraige/followers","following_url":"https://api.github.com/users/jakecraige/following{/other_user}","gists_url":"https://api.github.com/users/jakecraige/gists{/gist_id}","starred_url":"https://api.github.com/users/jakecraige/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakecraige/subscriptions","organizations_url":"https://api.github.com/users/jakecraige/orgs","repos_url":"https://api.github.com/users/jakecraige/repos","events_url":"https://api.github.com/users/jakecraige/events{/privacy}","received_events_url":"https://api.github.com/users/jakecraige/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-cocoa/labels/Help","name":"Help","color":"cc317c"}],"state":"open","locked":false,"assignee":{"login":"jpsim","id":474794,"avatar_url":"https://avatars.githubusercontent.com/u/474794?v=3","gravatar_id":"","url":"https://api.github.com/users/jpsim","html_url":"https://github.com/jpsim","followers_url":"https://api.github.com/users/jpsim/followers","following_url":"https://api.github.com/users/jpsim/following{/other_user}","gists_url":"https://api.github.com/users/jpsim/gists{/gist_id}","starred_url":"https://api.github.com/users/jpsim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpsim/subscriptions","organizations_url":"https://api.github.com/users/jpsim/orgs","repos_url":"https://api.github.com/users/jpsim/repos","events_url":"https://api.github.com/users/jpsim/events{/privacy}","received_events_url":"https://api.github.com/users/jpsim/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-10-06T22:57:12Z","updated_at":"2015-10-08T02:34:45Z","closed_at":null,"body":"I'd love to see support for doing a partial update when using the `realm.add(..., update: true);` API. As it currently stands it seems this is supported by the `realm.create(..., update: true)` and not from `realm.add`. \r\n\r\nThis is mentioned in the documentation like so when referencing `realm.create`:\r\n\r\n> You can also partially update objects with primary keys by passing the subset of values you wish to update, along with the primary key:\r\n\r\nI was able to track down test coverage of this feature(`.create`) to here\r\nhttps://github.com/realm/realm-cocoa/blob/master/Realm/Tests/ObjectTests.m#L1568-L1577\r\n\r\nI was able to write a failing spec describing the behavior and what I would like it to do here: https://github.com/realm/realm-cocoa/compare/master...jakecraige:jc-partial-update"},"comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments/146399753","html_url":"https://github.com/realm/realm-cocoa/issues/2644#issuecomment-146399753","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2644","id":146399753,"user":{"login":"jakecraige","id":3799709,"avatar_url":"https://avatars.githubusercontent.com/u/3799709?v=3","gravatar_id":"","url":"https://api.github.com/users/jakecraige","html_url":"https://github.com/jakecraige","followers_url":"https://api.github.com/users/jakecraige/followers","following_url":"https://api.github.com/users/jakecraige/following{/other_user}","gists_url":"https://api.github.com/users/jakecraige/gists{/gist_id}","starred_url":"https://api.github.com/users/jakecraige/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakecraige/subscriptions","organizations_url":"https://api.github.com/users/jakecraige/orgs","repos_url":"https://api.github.com/users/jakecraige/repos","events_url":"https://api.github.com/users/jakecraige/events{/privacy}","received_events_url":"https://api.github.com/users/jakecraige/received_events","type":"User","site_admin":false},"created_at":"2015-10-08T02:34:45Z","updated_at":"2015-10-08T02:34:45Z","body":"A more in depth overview of the data-flow through my app looks like so(using Argo for the JSON parsing):\r\n\r\nModels:\r\n\r\n```swift\r\nclass User: Object {\r\n    dynamic var id: Int = 0\r\n\r\n    override static func primaryKey() -> String? {\r\n        return \"id\"\r\n    }\r\n}\r\n\r\nclass Announcement: Object {\r\n    dynamic var id: Int = 0\r\n    dynamic var user: User?\r\n\r\n    override static func primaryKey() -> String? {\r\n        return \"id\"\r\n    }\r\n}\r\n\r\nextension Announcement: Decodable {\r\n    static func create(id id: Int, title: String, userId: Int) -> Announcement {\r\n        return Announcement(value: [\r\n            \"id\": id,\r\n            // this is the part that breaks because\r\n            // it wipes out existing user data when it saves\r\n            \"user\": [\"id\": userId] \r\n        ])\r\n    }\r\n\r\n    static func decode(j: JSON) -> Decoded<Announcement> {\r\n        return curry(Announcement.create)\r\n            <^> j <|  \"id\"\r\n            <*> j <|  \"user_id\"\r\n    }\r\n}\r\n\r\n// this is major psuedo-code, in the real world I'm using thoughtbot's Swish \r\n// but it's not really related to this PR.\r\nlet announcementsJSON = requestData()\r\nlet announcements: Decoded<[Announcement]> = announcementsJSON.map { announcementJSON in\r\n    return Announcement.decode(announcementJSON)\r\n}\r\n\r\nrealm.write {\r\n    realm.add(announcements, update: true)\r\n}\r\n```\r\n\r\nRight now I don't need the database until the end which feels really nice. I could do my own find or initialize from the id for the user but I'd need the database for that, lol. \r\n\r\nNot sure if that's super helpful but it's actually what I'm trying to do in the real world so maybe you'll have other ideas about how I can accomplish this. "}}