{"action":"created","issue":{"url":"https://api.github.com/repos/Sylius/Sylius/issues/3902","labels_url":"https://api.github.com/repos/Sylius/Sylius/issues/3902/labels{/name}","comments_url":"https://api.github.com/repos/Sylius/Sylius/issues/3902/comments","events_url":"https://api.github.com/repos/Sylius/Sylius/issues/3902/events","html_url":"https://github.com/Sylius/Sylius/issues/3902","id":127081928,"number":3902,"title":"Flaw with new Zone / Province structure","user":{"login":"peteward","id":7068515,"avatar_url":"https://avatars.githubusercontent.com/u/7068515?v=3","gravatar_id":"","url":"https://api.github.com/users/peteward","html_url":"https://github.com/peteward","followers_url":"https://api.github.com/users/peteward/followers","following_url":"https://api.github.com/users/peteward/following{/other_user}","gists_url":"https://api.github.com/users/peteward/gists{/gist_id}","starred_url":"https://api.github.com/users/peteward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peteward/subscriptions","organizations_url":"https://api.github.com/users/peteward/orgs","repos_url":"https://api.github.com/users/peteward/repos","events_url":"https://api.github.com/users/peteward/events{/privacy}","received_events_url":"https://api.github.com/users/peteward/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Sylius/Sylius/labels/RFC","name":"RFC","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2016-01-17T08:42:50Z","updated_at":"2016-01-20T14:04:46Z","closed_at":null,"body":"Hi,\r\n\r\nI'm just working through updating our app to the latest in master. I've got problems with Provinces and the new Zone structure. \r\n\r\nFirstly Provinces now MUST have a code (even though the provinces of some countries are not code-based). This is OK I guess, I've just set code = name for some countries that have this issue - GB for example.\r\n\r\nAt Reiss we have provinces for 4 countries so far that we ship to regularly - US, GB, Canada and Australia. However there seems to be a design requirement for code not only to be defined but also to be *unique*.\r\n\r\nThis is an issue in our dataset (which is not unusual). For example\r\n\r\n```\r\nID   COUNTRY_ID  NAME               CODE\r\n48\t 238\t     Washington\t        WA\r\n221\t 14\t         Western Australia  WA\r\n```\r\n\r\nHere we have 2 different countries that use identical codes because unlike countries there's no international standard for provinces and their codes.\r\n\r\nThis firstly breaks the DB structure of a requirement for a unique code. This is not really a major issue as we could just make the unique constraint on (`country_id`, `code`). However it does expose a fairly major flaw in the new Zone to ZoneMember architecture.\r\n\r\nMy understanding of the ZoneMember changes are that instead of ZoneMember relating to a Province or Country directly, a ZoneMember is ALWAYS a Zone, which then has a code which can relate to the 'external' entity by `type` and `code`. I think this is correct?\r\n\r\nIf so, this works fine for country but not for province, because province's code can't be unique due to the above situation. \r\n\r\nI can think of a few solutions but none of them seem perfectly clean to me. What do you think?\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Sylius/Sylius/issues/comments/173213175","html_url":"https://github.com/Sylius/Sylius/issues/3902#issuecomment-173213175","issue_url":"https://api.github.com/repos/Sylius/Sylius/issues/3902","id":173213175,"user":{"login":"michalmarcinkowski","id":7572437,"avatar_url":"https://avatars.githubusercontent.com/u/7572437?v=3","gravatar_id":"","url":"https://api.github.com/users/michalmarcinkowski","html_url":"https://github.com/michalmarcinkowski","followers_url":"https://api.github.com/users/michalmarcinkowski/followers","following_url":"https://api.github.com/users/michalmarcinkowski/following{/other_user}","gists_url":"https://api.github.com/users/michalmarcinkowski/gists{/gist_id}","starred_url":"https://api.github.com/users/michalmarcinkowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michalmarcinkowski/subscriptions","organizations_url":"https://api.github.com/users/michalmarcinkowski/orgs","repos_url":"https://api.github.com/users/michalmarcinkowski/repos","events_url":"https://api.github.com/users/michalmarcinkowski/events{/privacy}","received_events_url":"https://api.github.com/users/michalmarcinkowski/received_events","type":"User","site_admin":false},"created_at":"2016-01-20T14:04:46Z","updated_at":"2016-01-20T14:04:46Z","body":"After giving it some more thoughts I think we should go with the logic @pjedrzejewski proposed. Keep the unique code on Province (`US-FL`) and simply add a method  `getProvinceCodeWithoutCountryCode` to the model (can anyone come up with a better name, please?) that will return simply `FL`, so you can use it anywhere you need. This way we will have consistent data model and treat the `code` field exactly the same in the whole system."}}