{"action":"created","issue":{"url":"https://api.github.com/repos/Leadformance/hstore_translate/issues/39","repository_url":"https://api.github.com/repos/Leadformance/hstore_translate","labels_url":"https://api.github.com/repos/Leadformance/hstore_translate/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/Leadformance/hstore_translate/issues/39/comments","events_url":"https://api.github.com/repos/Leadformance/hstore_translate/issues/39/events","html_url":"https://github.com/Leadformance/hstore_translate/pull/39","id":38549037,"number":39,"title":"Add order_by feature","user":{"login":"jandudulski","id":153103,"avatar_url":"https://avatars.githubusercontent.com/u/153103?v=3","gravatar_id":"","url":"https://api.github.com/users/jandudulski","html_url":"https://github.com/jandudulski","followers_url":"https://api.github.com/users/jandudulski/followers","following_url":"https://api.github.com/users/jandudulski/following{/other_user}","gists_url":"https://api.github.com/users/jandudulski/gists{/gist_id}","starred_url":"https://api.github.com/users/jandudulski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jandudulski/subscriptions","organizations_url":"https://api.github.com/users/jandudulski/orgs","repos_url":"https://api.github.com/users/jandudulski/repos","events_url":"https://api.github.com/users/jandudulski/events{/privacy}","received_events_url":"https://api.github.com/users/jandudulski/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2014-07-23T16:55:09Z","updated_at":"2016-05-26T13:24:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Leadformance/hstore_translate/pulls/39","html_url":"https://github.com/Leadformance/hstore_translate/pull/39","diff_url":"https://github.com/Leadformance/hstore_translate/pull/39.diff","patch_url":"https://github.com/Leadformance/hstore_translate/pull/39.patch"},"body":"Simple shortcut which allows to order by translated column as described in readme."},"comment":{"url":"https://api.github.com/repos/Leadformance/hstore_translate/issues/comments/221869250","html_url":"https://github.com/Leadformance/hstore_translate/pull/39#issuecomment-221869250","issue_url":"https://api.github.com/repos/Leadformance/hstore_translate/issues/39","id":221869250,"user":{"login":"daniel-rikowski","id":1169363,"avatar_url":"https://avatars.githubusercontent.com/u/1169363?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-rikowski","html_url":"https://github.com/daniel-rikowski","followers_url":"https://api.github.com/users/daniel-rikowski/followers","following_url":"https://api.github.com/users/daniel-rikowski/following{/other_user}","gists_url":"https://api.github.com/users/daniel-rikowski/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-rikowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-rikowski/subscriptions","organizations_url":"https://api.github.com/users/daniel-rikowski/orgs","repos_url":"https://api.github.com/users/daniel-rikowski/repos","events_url":"https://api.github.com/users/daniel-rikowski/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-rikowski/received_events","type":"User","site_admin":false},"created_at":"2016-05-26T13:24:07Z","updated_at":"2016-05-26T13:24:07Z","body":"@rept This still won't work with fallbacks. \r\n\r\nImagine this fallback configuration:\r\n\r\n```ruby\r\nI18n.fallbacks[I18n.locale] == [:'de-DE', :de, :en]\r\n```\r\n\r\nAnd these database records:\r\n\r\n```ruby\r\n[\r\n  { name_translations: { 'de-DE' => 'Kanarienvogel', 'en-US' => 'Canary' },\r\n  { name_translations: { 'de' => 'März', 'en' => 'March' },\r\n  { name_translations: { 'en' => 'Wikipedia' },\r\n]\r\n```\r\nConsidering `I18n.locale = :'de-DE'` your SQL would sort these translations \r\n```sql\r\n'Kanarienvogel'\r\nNULL      -- should be 'März'\r\nNULL      -- should be 'Wikipedia'\r\n```\r\n\r\nTo achive correct sorting with fallbacks you have to generate a dynamic SQL statement which takes `I18n.fallbacks` into account. Like this:\r\n\r\n```sql\r\nSELECT ... ORDER BY COALESCE(\r\n    name_translations -> 'de-DE', \r\n    name_translations -> 'de', \r\n    name_translations -> 'en')\r\n```\r\n\r\nI've created a Gist with my - rather hacky - implementation. Use at your own risk!\r\nhttps://gist.github.com/daniel-rikowski/1d94ea943bbcf8935fd0f23a5c8b37f6\r\n\r\n**Example:**\r\n```ruby\r\nBook.order_translated(:title)\r\nAuthor.references(:books).order_translated(books: :title)\r\n```\r\n\r\n"}}
{"actor":{"display_login":"daniel-rikowski"}}