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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:08:16+00:00 2026-06-04T15:08:16+00:00

I have a Type has_many Dresses . In the Dress table, I have a

  • 0

I have a Type has_many Dresses. In the Dress table, I have a column called type_id which references the Type model. What I want to do is whenever a Type object is deleted, all of the associated Dress objects will update their type_id to nil.

So far, I tried this in the console and it works:

> Dress.where(type_id: 3).update_all(type_id: nil)

However, when I translate it in the TypesController like this:

def destroy
  type_id = params[:id]
  if Type.find(type_id).destroy
    Dress.where(:type_id => type_id).update_all(:type_id => nil)
    redirect_to admins_path
  end
end

…and try it in the browser, the Type object is deleted but the Dress type_id was not updated.

This is the log output:

DELETE FROM "types" WHERE "types"."id" = $1  [["id", 3]]
UPDATE "types" SET position = (position - 1) WHERE (1 = 1 AND position > 2)
COMMIT
UPDATE "dresses" SET "type_id" = NULL WHERE "dresses"."id"
  IN (SELECT "dresses"."id" FROM "dresses" WHERE "dresses"."type_id" = 0)

I don’t understand why it sets the type_id = 0 in the last UPDATE command but before that it was set correctly in the DELETE command.

  • 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-04T15:08:16+00:00Added an answer on June 4, 2026 at 3:08 pm
    class Type < ActiveRecord::Base
        has_many :dresses, :dependent => :nullify
        ...
    end
    

    Does not it work?

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

Sidebar

Related Questions

In database table I have column called options . It has type of integer
Imagine I have a model called Course and each course has_many Modules . However
Database: MySql 5.5.3 I have a type column in table topic , if the
I have a User model that has_many parents. I want that user model to
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have a struct which has several arrays within it. The arrays have type
I have a List<T> where T is my Event type which has a field
I have a bean of type string[] which has two or more values. I
I have a list of items of type ViewLookupItem which has these properties: For
Say I have a table animals that has a column parent_id Say also that

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.