app/models/behaviors/service.rb
def service *types
      provider = nil
      query_string = 'null=null'
      params = []
      types.each do |t|
        service_ancestors.each do |ancestor|
          query_string += " OR (service_overrides.target_type = ? AND service_overrides.target_id = ? AND st.name = ?)"
          params += [ancestor.class.name, ancestor[:id], t.is_a?(ServiceType) ? t.name.to_s : t.to_s]
        end
      end

      overrides = ServiceOverride.find(:all,
        :select => %Q(
          service_overrides.id,
          service_overrides.overridable,
          service_overrides.service_provider_id,
          st.name
        ),
        :joins => [
          'INNER JOIN service_providers AS sp ON service_overrides.service_provider_id = sp.id',
          'INNER JOIN service_types AS st on sp.service_type_id = st.id'
        ],
        :conditions => [query_string, *params]
      )

      ServiceProvider.find(:all, :conditions => { :id => overrides.collect { |o| o.overridable? ? o.service_provider_id : nil }})
    end
## Take a list of types, and find all services associated with them.  Written this was as an optimization
Take a list of types, and find all services associated with them.  Written this was as an optimization
Take a list of types and find all services associated with them . Written this was as an optimization
def service *types
      provider = nil
      query_string = 'null=null'
      params = []
      types.each do |t|
        service_ancestors.each do |ancestor|
          query_string += " OR (service_overrides.target_type = ? AND service_overrides.target_id = ? AND st.name = ?)"
          params += [ancestor.class.name, ancestor[:id], t.is_a?(ServiceType) ? t.name.to_s : t.to_s]
        end
      end
      overrides = ServiceOverride.find(:all,
        :select => %Q(
          service_overrides.id,
          service_overrides.overridable,
          service_overrides.service_provider_id,
          st.name
        ),
        :joins => [
          'INNER JOIN service_providers AS sp ON service_overrides.service_provider_id = sp.id',
          'INNER JOIN service_types AS st on sp.service_type_id = st.id'
        ],
        :conditions => [query_string, *params]
      )
      ServiceProvider.find(:all, :conditions => { :id => overrides.collect { |o| o.overridable? ? o.service_provider_id : nil }})
    end
def service * types provider = nil query_string = 'null=null' params = [ ] types . each do | t | service_ancestors . each do | ancestor | query_string += " OR (service_overrides.target_type = ? AND service_overrides.target_id = ? AND st.name = ?)" params += [ ancestor . class . name , ancestor [ :id ] , t . is_a? ( ServiceType ) ? t . name . to_s : t . to_s ] end end overrides = ServiceOverride . find ( :all , :select => %Q(
          service_overrides.id,
          service_overrides.overridable,
          service_overrides.service_provider_id,
          st.name
        ) , :joins => [ 'INNER JOIN service_providers AS sp ON service_overrides.service_provider_id = sp.id' , 'INNER JOIN service_types AS st on sp.service_type_id = st.id' ] , :conditions => [ query_string , * params ] ) ServiceProvider . find ( :all , :conditions => { :id => overrides . collect { | o | o . overridable? ? o . service_provider_id : nil } } ) end
Take a list of types, and find all services associated with them.
Take a list of types and find all services associated with them .
types