{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/2260","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2260/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2260/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2260/events","html_url":"https://github.com/realm/realm-cocoa/issues/2260","id":96225213,"number":2260,"title":"When updating object, it's relationship will be lost or it will be added twice","user":{"login":"shmidt","id":1472370,"avatar_url":"https://avatars.githubusercontent.com/u/1472370?v=3","gravatar_id":"","url":"https://api.github.com/users/shmidt","html_url":"https://github.com/shmidt","followers_url":"https://api.github.com/users/shmidt/followers","following_url":"https://api.github.com/users/shmidt/following{/other_user}","gists_url":"https://api.github.com/users/shmidt/gists{/gist_id}","starred_url":"https://api.github.com/users/shmidt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shmidt/subscriptions","organizations_url":"https://api.github.com/users/shmidt/orgs","repos_url":"https://api.github.com/users/shmidt/repos","events_url":"https://api.github.com/users/shmidt/events{/privacy}","received_events_url":"https://api.github.com/users/shmidt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"TimOliver","id":429119,"avatar_url":"https://avatars.githubusercontent.com/u/429119?v=3","gravatar_id":"","url":"https://api.github.com/users/TimOliver","html_url":"https://github.com/TimOliver","followers_url":"https://api.github.com/users/TimOliver/followers","following_url":"https://api.github.com/users/TimOliver/following{/other_user}","gists_url":"https://api.github.com/users/TimOliver/gists{/gist_id}","starred_url":"https://api.github.com/users/TimOliver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimOliver/subscriptions","organizations_url":"https://api.github.com/users/TimOliver/orgs","repos_url":"https://api.github.com/users/TimOliver/repos","events_url":"https://api.github.com/users/TimOliver/events{/privacy}","received_events_url":"https://api.github.com/users/TimOliver/received_events","type":"User","site_admin":false},"milestone":null,"comments":7,"created_at":"2015-07-21T04:42:35Z","updated_at":"2015-07-23T18:37:30Z","closed_at":null,"body":"```swift\r\npublic class Board: Object {\r\n    \r\n    let styles = List<Style>()\r\n    dynamic var id = \"\"\r\n    override public static func primaryKey() -> String? {\r\n        return \"id\"\r\n    }\r\n}\r\npublic class Style: Object {\r\n    dynamic var id = \"\"\r\n    override public static func primaryKey() -> String? {\r\n        return \"id\"\r\n    }\r\n}\r\n```\r\n\r\nI have some sync with Web API, \r\nand the problem is that when I update style object, it will be added to the board twice:\r\n\r\n```swift\r\n                    let queryRecordID = realm.objects(Style).filter(\"id == '\\(entry.id)'\")\r\n                    if queryRecordID.count == 0{\r\n                        //First time adding\r\n                           \r\n                        println(\"First time adding: \\(entry.id)\")\r\n                        realm.add(entry, update: false)\r\n                        board.styles.append(entry)\r\n                        styles.append(entry)\r\n                    }else{\r\n                        //Updating\r\n                        println(\"Updating: \\(entry.id)\")\r\n                        realm.add(entry, update: true)\r\n                        board.styles.append(entry)\r\n```\r\nIf I remove ```board.styles.append(entry)``` from updating part, then object will lose this relationship.                           "},"comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments/124203913","html_url":"https://github.com/realm/realm-cocoa/issues/2260#issuecomment-124203913","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/2260","id":124203913,"user":{"login":"segiddins","id":1946610,"avatar_url":"https://avatars.githubusercontent.com/u/1946610?v=3","gravatar_id":"","url":"https://api.github.com/users/segiddins","html_url":"https://github.com/segiddins","followers_url":"https://api.github.com/users/segiddins/followers","following_url":"https://api.github.com/users/segiddins/following{/other_user}","gists_url":"https://api.github.com/users/segiddins/gists{/gist_id}","starred_url":"https://api.github.com/users/segiddins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/segiddins/subscriptions","organizations_url":"https://api.github.com/users/segiddins/orgs","repos_url":"https://api.github.com/users/segiddins/repos","events_url":"https://api.github.com/users/segiddins/events{/privacy}","received_events_url":"https://api.github.com/users/segiddins/received_events","type":"User","site_admin":false},"created_at":"2015-07-23T18:37:30Z","updated_at":"2015-07-23T18:37:30Z","body":"I'd actually vote for everything but raw `add` or `create` doing an `update` under the hood if the object has a primary key, to simplify this scenario "}}