This project is archived and is in readonly mode.
Feature: has_many :through named_scope
-
josh
- State changed from new to invalid
I still think we are maintaining the policy of no "Feature Requests" without any sort implementation code.
I'd try the mailing list to see if anyone has any ideas how to do it.
-
Yong Bakos
- Tag set to activerecord, enhancement
Per johnnyb on the old Trac ticket
module ActiveRecord
class Base
def self.scoped_has_many_through(assoc, opts)
has_many_scope = opts.delete(:scope)
conditions_scope = Hash[*has_many_scope.to_a.map{|ent|
["#{opts[:through].to_s.pluralize}.#{ent[0]}", ent[1]]
}.flatten]
opts[:conditions] ||= {}
if opts[:conditions].is_a?(Hash)
opts[:conditions] = opts[:conditions].merge(conditions_scope)
else
raise "Conditions must be a hash for conditions_scope!"
end
has_many assoc, opts do
#Using define_method instead of def in order to make it lexically scoped
define_method(:construct_owner_attributes) do |reflection|
atts = super(reflection)
return atts.merge(has_many_scope)
end
end
end
end
end
scoped_has_many_through :reviewer_users, :through => :user_project_roles, :source => :user, :scope => { :role => "REVIEWER" }
-
Chris Hapgood
See this thread for recent discussion of this ticket as well as proposed solutions:
-
Ryan Bigg
Automatic cleanup of spam.