diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-03 19:42:29 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-03 19:43:29 +0530 |
commit | af5e1b4cc6fd3ae5f5e175751373a5e60934385b (patch) | |
tree | 3c044df83a27526741ba33084c991ad013f37eb0 /activerecord/lib/active_record/relation | |
parent | 22bfd8b09804db28e05e598e062d58fd2ab36485 (diff) | |
download | rails-af5e1b4cc6fd3ae5f5e175751373a5e60934385b.tar.gz rails-af5e1b4cc6fd3ae5f5e175751373a5e60934385b.tar.bz2 rails-af5e1b4cc6fd3ae5f5e175751373a5e60934385b.zip |
Add Relation#except
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index 7b15279253..b9e3457aac 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -45,5 +45,27 @@ module ActiveRecord alias :& :merge + def except(*skips) + result = Relation.new(@klass, table) + result.table = table + + [:eager_load, :preload, :includes].each do |load_method| + result = result.send(load_method, send(:"#{load_method}_associations")) + end + + result.readonly = self.readonly unless skips.include?(:readonly) + + result = result.joins(@relation.joins(@relation)) unless skips.include?(:joins) + result = result.group(@relation.groupings) unless skips.include?(:group) + result = result.limit(@relation.taken) unless skips.include?(:limit) + result = result.offset(@relation.skipped) unless skips.include?(:offset) + result = result.select(@relation.send(:select_clauses)) unless skips.include?(:select) + result = result.from(@relation.sources) unless skips.include?(:from) + result = result.order(order_clause) unless skips.include?(:order) + result = result.where(*@relation.wheres) unless skips.include?(:where) + + result + end + end end |