{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/4366","repository_url":"https://api.github.com/repos/realm/realm-cocoa","labels_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4366/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4366/comments","events_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4366/events","html_url":"https://github.com/realm/realm-cocoa/issues/4366","id":191568708,"number":4366,"title":"Model relationships can crash/thwart Model renaming migrations","user":{"login":"cbess","id":10981,"avatar_url":"https://avatars.githubusercontent.com/u/10981?v=3","gravatar_id":"","url":"https://api.github.com/users/cbess","html_url":"https://github.com/cbess","followers_url":"https://api.github.com/users/cbess/followers","following_url":"https://api.github.com/users/cbess/following{/other_user}","gists_url":"https://api.github.com/users/cbess/gists{/gist_id}","starred_url":"https://api.github.com/users/cbess/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbess/subscriptions","organizations_url":"https://api.github.com/users/cbess/orgs","repos_url":"https://api.github.com/users/cbess/repos","events_url":"https://api.github.com/users/cbess/events{/privacy}","received_events_url":"https://api.github.com/users/cbess/received_events","type":"User","site_admin":false},"labels":[{"id":154724428,"url":"https://api.github.com/repos/realm/realm-cocoa/labels/S:Waiting%20For%20User","name":"S:Waiting For User","color":"ededed","default":false},{"id":3303146,"url":"https://api.github.com/repos/realm/realm-cocoa/labels/T:Help","name":"T:Help","color":"cc317c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-24T17:25:52Z","updated_at":"2016-11-29T21:15:02Z","closed_at":null,"body":"## Goals\r\n\r\nRename a model from `BookmarkModel` to `Bookmark` (no `Model` suffix).\r\n\r\n## Expected Results\r\n\r\nThat at the end of the migration, using `migrate.create(...)`, it would \"move\" the old model data to the new model schema.\r\n\r\n## Actual Results\r\n\r\nIt crashed due to a duplicate `primaryKey` in one of the relationships. Basically, it tried to \"create\" every object (and nested objects) that was passed to `value`. I only wanted to \"create\" the `Bookmark`, but it instead attempted to \"create\" the `Tag` and then found a duplicate `primaryKey` (as it should, but not intended).\r\n\r\n## Steps to Reproduce\r\n\r\nCreate a model that has a \"to-many\" relationship to another model (like tags), then migrate using `Migration.create`. Both model and related model must have a `primaryKey` field. Realm will attempt to create an entry for each object and fail because it sees a duplicate key for the \"tags\".\r\n\r\n1. Create project using Realm that has two models\r\n1. Make model A have a \"to-many\" relationship to model B (eg. BookmarkModel to Tags)\r\n1. Change the name of model A to something else (eg. BookmarkData)\r\n1. During migration \"move\" the data to the new Schema, effectively \"renaming\" the schema\r\n\r\n## Code Sample\r\n\r\nNone\r\n\r\n## Version of Realm and Tooling\r\n\r\nRealm version: 2.1.0 (Swift)\r\n\r\nXcode version: 8.2\r\n\r\niOS/OSX version: iOS 10\r\n\r\nDependency manager + version: CocoaPods 1.1.0"},"comment":{"url":"https://api.github.com/repos/realm/realm-cocoa/issues/comments/263700962","html_url":"https://github.com/realm/realm-cocoa/issues/4366#issuecomment-263700962","issue_url":"https://api.github.com/repos/realm/realm-cocoa/issues/4366","id":263700962,"user":{"login":"cbess","id":10981,"avatar_url":"https://avatars.githubusercontent.com/u/10981?v=3","gravatar_id":"","url":"https://api.github.com/users/cbess","html_url":"https://github.com/cbess","followers_url":"https://api.github.com/users/cbess/followers","following_url":"https://api.github.com/users/cbess/following{/other_user}","gists_url":"https://api.github.com/users/cbess/gists{/gist_id}","starred_url":"https://api.github.com/users/cbess/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbess/subscriptions","organizations_url":"https://api.github.com/users/cbess/orgs","repos_url":"https://api.github.com/users/cbess/repos","events_url":"https://api.github.com/users/cbess/events{/privacy}","received_events_url":"https://api.github.com/users/cbess/received_events","type":"User","site_admin":false},"created_at":"2016-11-29T21:15:02Z","updated_at":"2016-11-29T21:15:02Z","body":"Thanks @jpsim for reviewing the issue. Mainly, I was hoping to have a way to skip the relationship or \"nested\" object creation. I didn't expect the `migration.create` to attempt to re-create relationships. \r\n\r\nI suppose that would be a feature request: \r\n```swift\r\nmigration.create(className: String, value: Any, traverse: Bool = true)\r\n```\r\nPerhaps?"}}
{"actor":{"display_login":"cbess"}}