Ruby on Rails Thursday, November 6, 2014

In case of counter cache, for example, how can I specify a condition to select the count of comments that I have marked as valid something like shown below

belongs_to :post, :counter_cache => true, :conditions => ["valid IS NOT NULL"]


On Thursday, November 6, 2014 3:47:39 PM UTC+5:30, Alvaro Naveda wrote:
The best solution i know to solve this issue with less number of queries is the counter_cache ;)

http://guides.rubyonrails.org/association_basics.html#counter-cache

El jueves, 6 de noviembre de 2014 07:40:42 UTC+1, Logesh m escribió:
I have a rails app where I need to take count of the associated model like post.comments.count and this loads up number of queries and I was searching for option to reduce this and found counter cache which saves the count in the table but is there any other option to find the count without saving in the table?

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a7df930d-6ae9-481a-8d31-dd81fa77c92a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment