Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6143697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:33:17+00:00 2026-05-23T18:33:17+00:00

Hello I want to create a query that goes something like this, Get me

  • 0

Hello I want to create a query that goes something like this, “Get me the variety which has the following ingredients(1,2,3)”

Here are my models

class Ingredient < ActiveRecord::Base
  has_and_belongs_to_many :varieties

class Variety < ActiveRecord::Base
  has_and_belongs_to_many :ingredients

I have been breaking my head but I haven’t been able to get it right, can someone help me out please. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:33:17+00:00Added an answer on May 23, 2026 at 6:33 pm

    Corrected after Dylan’s comment. I broke up the where_clause into a multi-line string for readability sake.

    ingredient_list = [1,2,3]
    where_clause = %{
    varieties.id IN
    (SELECT v.variety_id FROM 
    (SELECT variety_id, count(*) as cnt FROM ingredients_varieties WHERE ingredient_id in (#{ingredient_list.join(',')}) GROUP BY variety_id) v 
    WHERE v.cnt = #{ingredient_list.size})
    } 
    Variety.where(where_clause)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a string which contains something like this: hello this is an {test,
Hello I want to Create a home page that has updating blog entries. So
Hello I want to create a performance counter named as FileCopierApp , this should
Hello all, I need to create a query for house search, that would match
I want to create simple Spring MVC Hello world application that runs under Jetty
Hello This is a general question.I want to create a simple report just some
I want to create a function that receive multiples strings as parameters. Like the
Hello I want to create a regex to find words which have capital words
hello i want to get startet with programming with WIN32, therefore i wrote a
Hello fellow software developers. I want to distribute a C program which is scriptable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.