diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-08-18 07:50:11 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-08-18 07:50:11 -0300 |
commit | 79e951ca9bc875da9e4a19adeff3634f0b5b7b76 (patch) | |
tree | 3b46a3061cea3bc6a1d7a72d9e6f5c793a56663b /activerecord/lib/active_record/relation.rb | |
parent | c923409630a92d1a935699c1427702c822601165 (diff) | |
download | rails-79e951ca9bc875da9e4a19adeff3634f0b5b7b76.tar.gz rails-79e951ca9bc875da9e4a19adeff3634f0b5b7b76.tar.bz2 rails-79e951ca9bc875da9e4a19adeff3634f0b5b7b76.zip |
Use finder options as relation method names to provide more familiar
naming. Use bang methods convention in methods that alter the
relation.
Diffstat (limited to 'activerecord/lib/active_record/relation.rb')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 456de73250..bbbb1da210 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -1,7 +1,7 @@ module ActiveRecord class Relation delegate :delete, :to_sql, :to => :relation - CLAUSES_METHODS = ["project", "group", "order", "take", "skip", "on"].freeze + CLAUSES_METHODS = ["project", "where", "group", "order", "take", "skip", "on"].freeze attr_reader :relation, :klass def initialize(klass, table = nil) @@ -24,25 +24,41 @@ module ActiveRecord for clause in CLAUSES_METHODS class_eval %{ - def #{clause}(_#{clause}) + def #{clause}!(_#{clause}) @relation = @relation.#{clause}(_#{clause}) if _#{clause} self end } end - def join(joins, join_type = nil) - if !joins.blank? - if [String, Hash, Array, Symbol].include?(joins.class) - @relation = @relation.join(@klass.send(:construct_join, joins, nil)) + + def select!(selection) + @relation = @relation.project(selection) if selection + self + end + + def limit!(limit) + @relation = @relation.take(limit) if limit + self + end + + def offset!(offset) + @relation = @relation.skip(offset) if offset + self + end + + def joins!(join, join_type = nil) + if !join.blank? + if [String, Hash, Array, Symbol].include?(join.class) + @relation = @relation.join(@klass.send(:construct_join, join, nil)) else - @relation = @relation.join(joins, join_type) + @relation = @relation.join(join, join_type) end end self end - def where(conditions) + def conditions!(conditions) if !conditions.blank? conditions = @klass.send(:merge_conditions, conditions) if [String, Hash, Array].include?(conditions.class) @relation = @relation.where(conditions) |