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 5839947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:39:55+00:00 2026-05-22T11:39:55+00:00

Using active record, how can I return the results for a model if they

  • 0

Using active record, how can I return the results for a model if they do not exist in a certain relationship elsewhere. For example, say I have a Recipe model which belongs to categories (via a category_recipes join table).

So basically I have a Rake task that looks through each recipe and it’s description and try to put in in a category, but the task takes a long time and I’ll need to run it on a regular basis, so I only want to run it if the Recipe in question has not already been categorized and I’d rather not add a superfluous column like categorized, so I figure there is a way to retrieve only the Recipes that don’t exist in the join table. Any thoughts?

  • 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-22T11:39:55+00:00Added an answer on May 22, 2026 at 11:39 am

    Had to solve this myself today and think this will do the trick:

    Recipe.includes(:categories).where('categories.id IS NULL').references(:categories)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project using Castle Active Record. I stumbled across the
Let's say I have many-to-many relationship (using the ActiveRecord attribute HasAndBelongsToMany) between Posts and
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
Recently thanks to rails' popularity, many people start using activerecord as model. however, before
Rails uses the concept of migrations to deal with model changes using the ActiveRecord
We are running a website using Active Server Pages & COM+ components . The
I am creating a store using Active Merchant and PayPal sandbox right now. It
I'm looking at moving my application from using active directory membership provider to using
Using the tutorial Find Stuff (quick and Dirty) in Advance Rails Recipes, I can
I have recently been using cookie store and I want to transition to active

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.