Skip to content

Instantly share code, notes, and snippets.

@bradrobertson
Created April 14, 2013 16:26

Revisions

  1. bradrobertson created this gist Apr 14, 2013.
    21 changes: 21 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # Broken Example
    class Company < ActiveRecord::Base
    include IdentityCache
    cache_index :subdomain
    end

    Company.table_name = 'public.companies'

    Company.fetch_by_subdomain('app')
    # => SELECT id FROM companies WHERE subdomain = 'app' LIMIT 1


    # Fix for Broken Example
    class Company < ActiveRecord::Base
    self.table_name = 'public.companies'
    include IdentityCache
    cache_index :subdomain
    end

    Company.fetch_by_subdomain('app')
    # => SELECT id FROM public.companies WHERE subdomain = 'app' LIMIT 1