sql - How do I make an exclusive rather than inclusive query with named scopes in Rails? -
I have created an application that finds service providers based on many services. It is done through many mediums, so an object is included. Basically, if a user asks for service providers with Service A and Service B, then my returns give service providers who either offer both Service A and Service B or other service providers, who are offering a service or service B provide. Instead we
my radius looks like this:
named_scope: with_services, lambda {| Services | {: Terms = & gt; ["Services.id IN (# {services.map {| s | s.id}. Include (',')}) and service_options.service_owner_type = 'service provider' and service_options.service_owner_id = service_providers.id"] ,: Include = & gt; [: Services: Service_opher]}}
As you can see, I am using these operators to do this. But it's like saying "I am a service provider, who is a service or service b," when I really want, "I can find a service provider with both Service A and Service B".
Is it possible to filter in a single query of this type or will I need to compile the query through the results or just loop and remove them from the list if they are not all necessary services?
I think you can do this by providing a list of each of the services A.
Modify the scope of taking either of the two lists:
: conditions => ["Services.id IN (service_a) and services.id IN (service_b)"]
You may actually be able to call the radius twice
Model.edit_services (Service_A). In addition to these services, you can shortcode your array manipulation to find the ID: Services, with no additional cost,
.collect (& amp; id) .Join
& amp; ID: Equals block using ". O.O.ID"
Comments
Post a Comment