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

  • Home
  • SEARCH
  • 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 8564945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:18:38+00:00 2026-06-11T17:18:38+00:00

I have two Models, Product and Category, and a join table, Categorizations, for the

  • 0

I have two Models, Product and Category, and a join table, Categorizations, for the many-to-many relationship.

Let’s say I have two objects, product and category, that are instances of the above.

products = Product.new(...)
category = Category.new(...)
product.categories << category

This successfully creates the relationship in both directions in the rails console, so that:

product.categories
category.products

are both nonempty. Next:

product.categories.delete category

will delete the value from the product object and the join table. HOWEVER it will not delete it from the category object, so that:

category.products

is nonempty, which means that the in-memory category.products object is out of sync with the actual database. It seems weird to me that creation would work symmetrically but deletion would not.

Here are the relevant models:

class Product < ActiveRecord::Base
  has_many :categorizations, dependent: :destroy
  has_many :categories, through: :categorizations, :uniq => true
end

class Category < ActiveRecord::Base
  has_many :categorizations, dependent: :destroy
  has_many :products, through: :categorizations, :uniq => true
end

class Categorization < ActiveRecord::Base
  belongs_to :product, class_name: "Product"
  belongs_to :category, class_name: "Category"

  validates :product, presence: true
  validates :category, presence: true
end

Any ideas? Thanks!

  • 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-11T17:18:39+00:00Added an answer on June 11, 2026 at 5:18 pm

    Answer: it’s product.reload

    This explanation is the first one I’ve found after hours searching:
    https://stackoverflow.com/a/7449957/456280

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, say Product and Bundle. products table is related to product_prices
I have two models User and Category that have a HABTM association. I would
Let's say I have two models looking like this: class ProductType(models.Model): product_type = models.CharField(max_length=100)
I currently have two models: Product and Service. Both share the same table structure
I have two models, 'product' with 'belongs_to' and 'category' with 'has_many'. Product has a
I'm making an online shop. I have two models: Product and Category . Product
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories
I have two models. one is brand and another is product_detail. brands table has
I have two Models, Programme and Event, a programme has many events. I need
I have two models: Price :belongs_to Products Product :has_many Prices I created new Prices

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.