Skip to content

Commit

Permalink
added origin and origin_attribute to ActiveRecord::Relation [#835 sta…
Browse files Browse the repository at this point in the history
…te:resolved]
  • Loading branch information
ddnexus committed Oct 26, 2010
1 parent 0671d3c commit 5c190e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions hobo/lib/hobo/engine.rb
Expand Up @@ -27,6 +27,7 @@ class Engine < Rails::Engine
require 'hobo/extensions/active_record/hobo_methods'
require 'hobo/extensions/active_record/permissions'
require 'hobo/extensions/active_record/scopes'
require 'hobo/extensions/active_record/relation_with_origin'
require 'hobo/extensions/active_model/name'
require 'hobo/extensions/active_model/translation'
end
Expand Down
28 changes: 28 additions & 0 deletions hobo/lib/hobo/extensions/active_record/relation_with_origin.rb
@@ -0,0 +1,28 @@
module ActiveRecord

class Relation
attr_accessor :origin, :origin_attribute
end

module Associations
class AssociationCollection

def scoped_with_origin
relation = scoped_without_origin
relation.origin = @owner
relation.origin_attribute = @reflection.name
relation
end
alias_method_chain :scoped, :origin

def method_missing_with_origin(method, *args)
res = method_missing_without_origin(method, *args)
res.origin = @owner if res.respond_to?(:origin)
res.origin_attribute = @reflection.name if res.respond_to?(:origin_attribute)
res
end
alias_method_chain :method_missing, :origin

end
end
end

0 comments on commit 5c190e8

Please sign in to comment.