{"action":"created","issue":{"url":"https://api.github.com/repos/hyperoslo/Sync/issues/84","labels_url":"https://api.github.com/repos/hyperoslo/Sync/issues/84/labels{/name}","comments_url":"https://api.github.com/repos/hyperoslo/Sync/issues/84/comments","events_url":"https://api.github.com/repos/hyperoslo/Sync/issues/84/events","html_url":"https://github.com/hyperoslo/Sync/issues/84","id":70116277,"number":84,"title":"Many to Many Issue","user":{"login":"ashkan18","id":1230819,"avatar_url":"https://avatars.githubusercontent.com/u/1230819?v=3","gravatar_id":"","url":"https://api.github.com/users/ashkan18","html_url":"https://github.com/ashkan18","followers_url":"https://api.github.com/users/ashkan18/followers","following_url":"https://api.github.com/users/ashkan18/following{/other_user}","gists_url":"https://api.github.com/users/ashkan18/gists{/gist_id}","starred_url":"https://api.github.com/users/ashkan18/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashkan18/subscriptions","organizations_url":"https://api.github.com/users/ashkan18/orgs","repos_url":"https://api.github.com/users/ashkan18/repos","events_url":"https://api.github.com/users/ashkan18/events{/privacy}","received_events_url":"https://api.github.com/users/ashkan18/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hyperoslo/Sync/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-22T12:51:14Z","updated_at":"2015-04-24T13:38:07Z","closed_at":"2015-04-24T08:55:06Z","body":"I had issues with Many to Many relationships. I found the problem happens at this line:\r\n```\r\nchildPredicate = [NSPredicate predicateWithFormat:@\"ANY %K.%K = %@\", relationshipName, destinationLocalKey, [children valueForKey:destinationRemoteKey]];\r\n```\r\nI noticed that we generate a predicate that points to the child but since it has relationshipName in it, it ends up being invalid predicate. \r\n\r\nHere are the models diagram:\r\n![models](https://cloud.githubusercontent.com/assets/1230819/7274747/79c8eee6-e8cd-11e4-9526-de105941d8bf.png)\r\n\r\nThe predicate that that line generates is \r\n```\r\nANY fulfillers.xid = (<some xids>)\r\n```\r\nBut it does it on fulfillers Model. \r\n\r\nHere is a JSON sample:\r\n```json\r\n{\r\n  \"xid\":\"mstaff_F58dVBTsXznvMpCPmpQgyV\",\r\n  \"user\":{\r\n    \"full_name\":\"Ashkan Nasseri\",\r\n    \"email\":\"a@b.com\",\r\n    \"phone\":\"###-###-####\",\r\n    \"xid\":\"usr_8YQhMfiLvXEg6TaD7YKyjL\",\r\n    \"photo_inventory\":true\r\n  },\r\n  \"image\":\"a.jpg\",\r\n  \"image_xs\":\"s.jpg\",\r\n  \"fulfillers\":[\r\n    {\r\n      \"xid\":\"ffr_AkAHQegYkrobp5xc2ySc5D\",\r\n      \"name\":\"New York\"\r\n    },\r\n    {\r\n      \"xid\":\"ffr_n5eGjfHQRqKr4tAfL7RNi9\",\r\n      \"name\":\"Chicago\"\r\n    }\r\n  ],\r\n  \"current_vehicle\":{\r\n    \"xid\":\"vhc_test\",\r\n    \"name\":\"Test\"\r\n  }\r\n}\r\n```\r\n \r\nI fixed the problem by removing %k. and relationshipName from the predicate generation, everything works fine for me now but it breaks testCustomPrimaryKey.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/hyperoslo/Sync/issues/comments/95934511","html_url":"https://github.com/hyperoslo/Sync/issues/84#issuecomment-95934511","issue_url":"https://api.github.com/repos/hyperoslo/Sync/issues/84","id":95934511,"user":{"login":"3lvis","id":1088217,"avatar_url":"https://avatars.githubusercontent.com/u/1088217?v=3","gravatar_id":"","url":"https://api.github.com/users/3lvis","html_url":"https://github.com/3lvis","followers_url":"https://api.github.com/users/3lvis/followers","following_url":"https://api.github.com/users/3lvis/following{/other_user}","gists_url":"https://api.github.com/users/3lvis/gists{/gist_id}","starred_url":"https://api.github.com/users/3lvis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/3lvis/subscriptions","organizations_url":"https://api.github.com/users/3lvis/orgs","repos_url":"https://api.github.com/users/3lvis/repos","events_url":"https://api.github.com/users/3lvis/events{/privacy}","received_events_url":"https://api.github.com/users/3lvis/received_events","type":"User","site_admin":false},"created_at":"2015-04-24T13:38:07Z","updated_at":"2015-04-24T13:38:07Z","body":"Thanks! 🍻\r\n![giphy](https://cloud.githubusercontent.com/assets/1088217/7319728/e2f9e9d0-ea97-11e4-8dd5-3486ccbd8627.gif)\r\n"}}