README.md in dase-3.2.2 vs README.md in dase-3.2.4
- old
+ new
@@ -35,30 +35,38 @@
Author.includes_count_of(:articles).find_each do |author|
puts "#{author.name} has #{author.articles_count} articles published"
end
```
-### Advanced usage:
-
-You can specify a hash of options which will be passed to the underlying finder
+### Using :conditions hash
+Specify a hash of options which will be passed to the underlying finder
which retrieves the association. Valid keys are: :conditions, :group, :having, :joins, :include
```
-Author.includes_count_of(:articles, :conditions => {:year => 2012})
+Author.includes_count_of(:articles, :conditions => {:year => 2012}) # counts only articles in year 2012
```
+### Using scope merging
+```
+scope = Article.where(:year => 2012)
+Author.includes_count_of(:articles, :only => scope) # counts only articles in year 2012
+```
-### Known problems
+### Using block syntax
+```
+Author.includes_count_of(:articles){ where(:year => 2012) } # in the block, 'self' is a Relation instance
+Author.includes_count_of(:articles){ |scope| scope.where(:year => 2012) } # 'self' is the same inside and outside the block
+```
-1. Dase doesn't support :through option on associations
-2. You can't put includes_count_of calls into a scope declaration, like this:
-
+### Renaming counter column
```
-class Author
- scope :with_counters, lambda {
- includes_count_of(:articles) # this will not work!!!
- }
-end
+sites = WebSite.includes_count_of(:users, :conditions => {:role => 'admin'}, :as => :admins_count)
+sites.each { |site| puts "Site #{site.url} has #{site.admins_count} admin users" }
```
+
+
+### Known problems
+
+Dase doesn't support polymorphism.
## How it works
Here's a pseudo-code that gives an idea on how it works internally
```