{"action":"created","issue":{"url":"https://api.github.com/repos/jeremyevans/sequel/issues/1516","repository_url":"https://api.github.com/repos/jeremyevans/sequel","labels_url":"https://api.github.com/repos/jeremyevans/sequel/issues/1516/labels{/name}","comments_url":"https://api.github.com/repos/jeremyevans/sequel/issues/1516/comments","events_url":"https://api.github.com/repos/jeremyevans/sequel/issues/1516/events","html_url":"https://github.com/jeremyevans/sequel/issues/1516","id":327771855,"number":1516,"title":"Effect of sorting of keys in create_join_table on name and index","user":{"login":"yb66","id":326444,"avatar_url":"https://avatars0.githubusercontent.com/u/326444?v=4","gravatar_id":"","url":"https://api.github.com/users/yb66","html_url":"https://github.com/yb66","followers_url":"https://api.github.com/users/yb66/followers","following_url":"https://api.github.com/users/yb66/following{/other_user}","gists_url":"https://api.github.com/users/yb66/gists{/gist_id}","starred_url":"https://api.github.com/users/yb66/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yb66/subscriptions","organizations_url":"https://api.github.com/users/yb66/orgs","repos_url":"https://api.github.com/users/yb66/repos","events_url":"https://api.github.com/users/yb66/events{/privacy}","received_events_url":"https://api.github.com/users/yb66/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-05-30T15:01:10Z","updated_at":"2018-05-30T16:10:35Z","closed_at":"2018-05-30T16:08:54Z","author_association":"CONTRIBUTOR","body":"Hi Jeremy,\r\n\r\n### Complete Description of Issue\r\n\r\nI noticed that `create_join_table` names the table alphabetically, e.g.\r\n\r\n     create_join_table(  user_id: :users, team_id: :teams )\r\n\r\nwill create a table called `teams_users` when I expected `users_teams`.\r\n\r\n[This line](https://github.com/jeremyevans/sequel/blob/master/lib/sequel/database/schema_methods.rb#L113) sorts the keys.\r\n\r\n```\r\ndef create_join_table(hash, options=OPTS)\r\n      keys = hash.keys.sort\r\n```\r\n\r\nI'm wondering if either the docs should be updated to mention this, as the example given is already sorted (cats and dogs) so it's not obvious, or, to change the method so the keys aren't sorted.\r\n\r\nI lean towards not sorting the keys for 2 reasons:\r\n\r\n1. Mainly because if I write it one way the accompanying `down` statement in a migration is likely to be written to mirror the order, e.g. `drop_table :users_teams`.\r\n2. A [composite primary key is created](https://github.com/jeremyevans/sequel/blob/master/lib/sequel/database/schema_methods.rb#L123) and order may matter (this may be old info that's still in my head so let me know if I'm wrong). There may some other reason for the sort that I'm unaware of. Looking at the code I notice there's [an index of the reverse name order created](https://github.com/jeremyevans/sequel/blob/master/lib/sequel/database/schema_methods.rb#L124) so perhaps this isn't an issue.\r\n\r\nI can add the `name` option but that was fiddly to get right and starts getting ugly quickly, even without extra options:\r\n\r\n    create_join_table({ \r\n        user_id: :users,\r\n        team_id: :teams,\r\n      },\r\n       name: :users_teams\r\n    )\r\n\r\nEither way, I'm happy to add the note/remove the sort, I wanted to get your thoughts first.\r\n\r\nRegards,\r\niain\r\n\r\n### Simplest Possible Self-Contained Example Showing the Bug\r\n\r\n    create_join_table(  cat_id: :cats, dog_id: :dogs )\r\n\r\nproduces the same table as\r\n\r\n    create_join_table(  dog_id: :dogs, cat_id: :cats )\r\n\r\n### Full Backtrace of Exception (if any)\r\n\r\n\r\n\r\n### SQL Log (if any)\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/jeremyevans/sequel/issues/comments/393220976","html_url":"https://github.com/jeremyevans/sequel/issues/1516#issuecomment-393220976","issue_url":"https://api.github.com/repos/jeremyevans/sequel/issues/1516","id":393220976,"user":{"login":"yb66","id":326444,"avatar_url":"https://avatars0.githubusercontent.com/u/326444?v=4","gravatar_id":"","url":"https://api.github.com/users/yb66","html_url":"https://github.com/yb66","followers_url":"https://api.github.com/users/yb66/followers","following_url":"https://api.github.com/users/yb66/following{/other_user}","gists_url":"https://api.github.com/users/yb66/gists{/gist_id}","starred_url":"https://api.github.com/users/yb66/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yb66/subscriptions","organizations_url":"https://api.github.com/users/yb66/orgs","repos_url":"https://api.github.com/users/yb66/repos","events_url":"https://api.github.com/users/yb66/events{/privacy}","received_events_url":"https://api.github.com/users/yb66/received_events","type":"User","site_admin":false},"created_at":"2018-05-30T16:10:35Z","updated_at":"2018-05-30T16:10:35Z","author_association":"CONTRIBUTOR","body":"Hi,\r\n\r\nThat's fine, I'm just wondering if a note in the method docs would be nice?\r\n\r\nRegards,\r\niain"}}
{"actor":{"display_login":"yb66"}}