{"action":"opened","issue":{"url":"https://api.github.com/repos/sinalpha/sinalpha.github.io/issues/69","labels_url":"https://api.github.com/repos/sinalpha/sinalpha.github.io/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/sinalpha/sinalpha.github.io/issues/69/comments","events_url":"https://api.github.com/repos/sinalpha/sinalpha.github.io/issues/69/events","html_url":"https://github.com/sinalpha/sinalpha.github.io/issues/69","id":113513809,"number":69,"title":"counter_cache: true 历史数据库遗留问题","user":{"login":"sinalpha","id":4320960,"avatar_url":"https://avatars.githubusercontent.com/u/4320960?v=3","gravatar_id":"","url":"https://api.github.com/users/sinalpha","html_url":"https://github.com/sinalpha","followers_url":"https://api.github.com/users/sinalpha/followers","following_url":"https://api.github.com/users/sinalpha/following{/other_user}","gists_url":"https://api.github.com/users/sinalpha/gists{/gist_id}","starred_url":"https://api.github.com/users/sinalpha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sinalpha/subscriptions","organizations_url":"https://api.github.com/users/sinalpha/orgs","repos_url":"https://api.github.com/users/sinalpha/repos","events_url":"https://api.github.com/users/sinalpha/events{/privacy}","received_events_url":"https://api.github.com/users/sinalpha/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-10-27T06:15:08Z","updated_at":"2015-10-27T06:15:08Z","closed_at":null,"body":"[参考：Three Easy Steps to Using Counter Caches in Rails](http://yerb.net/blog/2014/03/13/three-easy-steps-to-using-counter-caches-in-rails/)\r\n\r\n\r\n\r\n对于遗留下来的数据库（legacy database），需要`Model.reset_counters`一下：\r\n\r\n~~~\r\nServer.find_each { |s| Server.reset_counters(s.id, :routers) }\r\nServer.find_each { |s| Server.reset_counters(s.id, :ss_services) }\r\n~~~"}}