Module: BetterAr::AssociationCollection
- Defined in:
- lib/better_ar/association_collection.rb
Instance Method Summary collapse
-
#count(column_name = nil, count_options = {}) ⇒ Object
Allows for the same interface as Relation#count on association collections.
-
#first(opts = {}) ⇒ Object
Allows for the same interface as Relation#first on association collections.
Instance Method Details
#count(column_name = nil, count_options = {}) ⇒ Object
Allows for the same interface as Relation#count on association collections
example:
User.first.records.count(:level => 2)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/better_ar/association_collection.rb', line 29 def count(column_name = nil, = {}) if column_name.is_a?(Hash) = column_name column_name = nil end if .empty? super elsif .key?(:conditions) super(column_name, ) else scope.where().count end end |
#first(opts = {}) ⇒ Object
Allows for the same interface as Relation#first on association collections
example:
User.first.records.first(:level => 2, :order! => :name)
11 12 13 14 15 16 17 18 19 |
# File 'lib/better_ar/association_collection.rb', line 11 def first(opts = {}) if opts.empty? super elsif opts.key?(:conditions) super(opts) else scoped.first(opts) end end |