I'm using the multi-db gem with Slony-I replication on PostgreSQL in a Rails app. This mostly works perfectly, but there is a bit of a replication lag in certain cases. One of the cases involves an ActiveRecord counter_cache.
For clarity, assume the following two models:
class Post < ActiveRecord::Base
has_many :comments
...
end
class Comment < ActiveRecord::Base
belongs_to :post, :counter_cache => true, :touch => true
...
end
After the creation of a comment, rjs is called to update comments count with:
@comment.post.comments_count
With multi-db turned off (or the entry for the slave database pointing the the master db), this works fine. So, I tried something like this:
ActiveRecord::Base.connection_proxy.with_master do
[email protected]
count=post.comments_count
end
This still gives a stale result. As does setting:
config.cache_classes = false
It looks like the call to with_master
isn't working. Any advice on how to determine which database multi-db is using? Or, alternatively, on how to deal with such issues?