Skip to content

Commit

Permalink
replace includes and join parent with eager_load
Browse files Browse the repository at this point in the history
  • Loading branch information
hzamani committed Jul 22, 2014
1 parent 66cdc56 commit cc16982
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
4 changes: 1 addition & 3 deletions lib/active_record/acts_as_relation.rb
Expand Up @@ -13,11 +13,9 @@ def acts_as(model_name, scope = nil, options = {})
class_eval do
include ActiveRecord::ActsAsRelation::ActsAsModules[acts_as]

default_scope -> { includes(acts_as.name) }
default_scope -> { eager_load(acts_as.name) }
end

class_eval { default_scope -> { joins(acts_as.name) } } if options.fetch :auto_join, true

instance_eval <<-EndCode, __FILE__, __LINE__ + 1
def acts_as_other_model?
true
Expand Down
4 changes: 0 additions & 4 deletions spec/acts_as_relation_spec.rb
Expand Up @@ -169,10 +169,6 @@
expect { Pen.where('price > 1').to_a }.not_to raise_error
expect(Pen.where('name = ?', 'RedPen')).to include(pen)
end

it 'can be disabled by setting auto_join option to false' do
expect { Pencil.where('name = 1').to_a }.to raise_error(ActiveRecord::StatementInvalid)
end
end
end
end
Expand Down

0 comments on commit cc16982

Please sign in to comment.