{"issue":{"pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"state":"open","milestone":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/6c942d7234aacc386a613c7e8a6715b3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"6c942d7234aacc386a613c7e8a6715b3","url":"https://api.github.com/users/noefroidevaux","login":"noefroidevaux","id":37739},"labels":[],"updated_at":"2011-11-10T11:15:47Z","assignee":null,"closed_at":null,"comments":0,"url":"https://api.github.com/repos/rails/rails/issues/3595","body":"Hi,\r\n\r\nFor example, if we have a Document model with a parent_id and privacy attributes (with \"belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Document'\"), I try to have a query like:\r\n\r\n```ruby\r\nDocument.joins(:parent).where(\"parents_documents.privacy = ?\", 1)\r\n```\r\n\r\nEvery time I run this query, a call is made on database with \"SHOW TABLES\", because ActiveRecord don't cache the table which is not in database.\r\n\r\nIn ConnectionPool (lib/active_record/connection_adapters/abstract/connection_pool.rb), currently, we have:\r\n\r\n```ruby\r\ndef table_exists?(name)\r\n  return true if @tables.key? name\r\n\r\n  with_connection do |conn|\r\n    conn.tables.each { |table| @tables[table] = true }\r\n      @tables[name] = true if !@tables.key?(name) && conn.table_exists?(name)\r\n    end\r\n\r\n  @tables.key? name\r\nend\r\n```\r\n\r\nI propose to change to:\r\n\r\n```ruby\r\ndef table_exists?(name)\r\n  return @tables[name] if @tables.key? name\r\n\r\n    with_connection do |conn|\r\n      conn.tables.each { |table| @tables[table] = true }\r\n    @tables[name] = !@tables.key?(name) && conn.table_exists?(name) ? true : false\r\n  end\r\n\r\n  @tables[name] if @tables.key? name\r\nend\r\n```\r\n\r\nWhat do you think? It is the right way?","html_url":"https://github.com/rails/rails/issues/3595","number":3595,"title":"[ActiveRecord] Add a condition on the join table make multiple SHOW TABLES calls","id":2196891,"created_at":"2011-11-10T11:15:47Z"},"action":"opened"}