diff options
author | Tarmo Tänav <tarmo@itech.ee> | 2008-08-26 19:29:16 +0300 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-08-27 23:32:21 -0700 |
commit | 96c6fe084228d570dad80e3100830edb2bc0448d (patch) | |
tree | f573cc36df43094cb2b9f7a5cf6ba3406e5edb24 /activerecord/lib | |
parent | 13671cc565aad2327f81a29789154b829ceeda04 (diff) | |
download | rails-96c6fe084228d570dad80e3100830edb2bc0448d.tar.gz rails-96c6fe084228d570dad80e3100830edb2bc0448d.tar.bz2 rails-96c6fe084228d570dad80e3100830edb2bc0448d.zip |
Implement count limit/offset support for has_many associations
[#348 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index ce62127505..1535995410 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -14,7 +14,16 @@ module ActiveRecord @finder_sql + " AND (#{sanitize_sql(options[:conditions])})" options[:include] ||= @reflection.options[:include] - @reflection.klass.count(column_name, options) + value = @reflection.klass.count(column_name, options) + + limit = @reflection.options[:limit] + offset = @reflection.options[:offset] + + if limit || offset + [ [value - offset.to_i, 0].max, limit.to_i ].min + else + value + end end end |