{"action":"closed","issue":{"url":"https://api.github.com/repos/tchandy/octopus/issues/203","labels_url":"https://api.github.com/repos/tchandy/octopus/issues/203/labels{/name}","comments_url":"https://api.github.com/repos/tchandy/octopus/issues/203/comments","events_url":"https://api.github.com/repos/tchandy/octopus/issues/203/events","html_url":"https://github.com/tchandy/octopus/issues/203","id":22607932,"number":203,"title":"\"using\" method inside another method in model","user":{"login":"noff","id":937186,"avatar_url":"https://avatars.githubusercontent.com/u/937186?v=3","gravatar_id":"","url":"https://api.github.com/users/noff","html_url":"https://github.com/noff","followers_url":"https://api.github.com/users/noff/followers","following_url":"https://api.github.com/users/noff/following{/other_user}","gists_url":"https://api.github.com/users/noff/gists{/gist_id}","starred_url":"https://api.github.com/users/noff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noff/subscriptions","organizations_url":"https://api.github.com/users/noff/orgs","repos_url":"https://api.github.com/users/noff/repos","events_url":"https://api.github.com/users/noff/events{/privacy}","received_events_url":"https://api.github.com/users/noff/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2013-11-13T17:35:37Z","updated_at":"2015-10-04T20:47:49Z","closed_at":"2015-10-04T20:47:49Z","body":"Hello. Have different shards and tables for one big list of elements.\r\nTrying to simplify method of reading rows from shards.\r\n\r\nTrying to use this construction\r\n\r\n`links = Link.set_table_for_user(user_id).where(user_id: user_id)`\r\n\r\nIn model:\r\n```\r\nclass Link < ActiveRecord::Base\r\n\r\n  def self.set_table_for_user(user_id)\r\n    using(get_shard_name_by_user_id user_id)\r\n    self.table_name = Link.get_table_name_by_user_id(user_id)\r\n    self.all\r\n  end\r\n\r\n  def self.get_table_name_by_user_id(user_id)\r\n    n = '%02d' % (user_id.to_s.slice(0,10).to_i(16)%100) # transform '1' to '01'\r\n    return \"link_texts_#{n}\"\r\n  end\r\n\r\nend\r\n```\r\n\r\nSo, block `using` inside of method is not works. Octopus trying to find rows in :master shard, not calculated shard.\r\n\r\nIt works if I write:\r\n```\r\nshard = Link.get_shard_name_by_user_id(user_id)\r\nLink.using(shard).set_table_for_user(user_id).where(user_id: user_id)\r\n```\r\n\r\nAny method to use \"using\" inside static method of model?"}}