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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:40:05+00:00 2026-06-09T22:40:05+00:00

I use association to map between my Store model and my Product model, using

  • 0

I use association to map between my Store model and my Product model, using Store has_many :products and Product belongs_to :store. In this case, I can simply get store info and all products of the store using this simple code:

@store = Store.find_by_id params[:store_id]

But, I recently added a status field to products. This status is set by default to ON and when the user wants to destroy a product, this status is set to OFF instead of deleting the product on database.

But in this case, in the previous code, I get all products (whatever the product status is).

Question: How can I get store info AND ONLY products with :status => ‘ON’?

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-06-09T22:40:07+00:00Added an answer on June 9, 2026 at 10:40 pm

    You can use default scope for your model

    class Product < ActiveRecord::Base
      default_scope where(status: "on")
    end
    

    update:

    You can skip default scope like that:

    @store.products.unscoped
    

    If you don’t want to use default scope you can try this:

    @store.products.where(status: "on")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Related (for the no-association-object use case): SQLAlchemy Many-to-Many Relationship on a Single Table Building
for instance, I have 2 model Drummer and Video If I use one-to-many association
I am using NHibernate and have a many-to-many association between an Employee and a
I'm trying to map two objects to each other using a ManyToMany association, but
Use Case Show a photo uploaded by the user in a square box with
I just finished using Linq to Sql to map our existing Database structure for
I'm trying to use association proxy for tags, in a very similar scenario to
I need to use tables from a DB which I cannot alter (using linked
So, I'm using a std::map as an associative array. The map is declared as
I'm looking for a class in java that has key-value association, but without using

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.