forked from newtonapple/db-charmer
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix association preloading in rails 3.2
- Loading branch information
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
lib/db_charmer/rails32/active_record/preloader/association.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
module DbCharmer | |||
module ActiveRecord | |||
module Preloader | |||
module Association | |||
extend ActiveSupport::Concern | |||
included do | |||
alias_method_chain :build_scope, :db_magic | |||
end | |||
|
|||
def build_scope_with_db_magic | |||
if model.db_charmer_top_level_connection? || reflection.options[:polymorphic] || | |||
model.db_charmer_default_connection != klass.db_charmer_default_connection | |||
build_scope_without_db_magic | |||
else | |||
build_scope_without_db_magic.on_db(model) | |||
end | |||
end | |||
end | |||
end | |||
end | |||
end |
23 changes: 23 additions & 0 deletions
23
lib/db_charmer/rails32/active_record/preloader/has_and_belongs_to_many.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
module DbCharmer | |||
module ActiveRecord | |||
module Preloader | |||
module HasAndBelongsToMany | |||
extend ActiveSupport::Concern | |||
included do | |||
alias_method_chain :records_for, :db_magic | |||
end | |||
|
|||
def records_for_with_db_magic(ids) | |||
if model.db_charmer_top_level_connection? || reflection.options[:polymorphic] || | |||
model.db_charmer_default_connection != klass.db_charmer_default_connection | |||
records_for_without_db_magic(ids) | |||
else | |||
klass.on_db(model) do | |||
records_for_without_db_magic(ids) | |||
end | |||
end | |||
end | |||
end | |||
end | |||
end | |||
end |
f050d90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this was removed in the general rails branch, and google found me this. Did you reimplement from how they seemed to do it before, or just make it up again?
f050d90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't removed in the rails master. I used the word 'reimplement' because it was removed in this project (db-charmer) before.
http://edgeapi.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-preload and http://edgeapi.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-includes are still there in master
f050d90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the link, I appreciate it :)
f050d90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea on the difference between preload and includes?