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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:30:31+00:00 2026-06-04T11:30:31+00:00

Using a rails console I create a Model record, then retrieve using a new

  • 0

Using a rails console I create a Model record, then retrieve using a new variable and update some fields:

var = MyModel.new
var.name = "my name"
var.save

var2 = MyModel.last
var2.name = "your name"
var2.save

now going back to the old variable var.save simply returns true and won’t overwrite the name field to its value: "my name"

Why’s that?

  • 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-04T11:30:32+00:00Added an answer on June 4, 2026 at 11:30 am

    Rails Models are ‘Dirty’ by default, meaning that attribute setting functions, attribute=(), mark the attribute as changed and tell Rails to update this attribute on the next save. This info is stored on the model, NOT in the database. On var.save, Rails only updates attributes it knows to have changed. Rails does not check the database for a discrepancy if it thinks nothing has changed (this would be incredibly slow in a production environment).

    You can use var.reload to reload attributes from the database into the corresponding object.

    EDIT: To clarify the comments being made above, you should be using MyModel.last not MyModel.first in your test code. If you have more than one row in your database, MyModel.first will not refer to the most recently saved object, and therefore var2 and var will refer to completely different objects.

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

Sidebar

Related Questions

I have been using the Rails console a fair bit lately and its making
Using Rails ActiveRecord, am wanting to calculate the time between two datetime fields within
When using Rails date_select with :prompt => true I see some very strange behavior
I wanted to create PDFs for my rails application using wkhtml2pdf and wicked_pdf. I
I'm using Devise and CanCan to create a backbone.js front-end and Rails 3.0.7 for
I am using Ruby on Rails to create a website for a game I
I'm trying to create an appointment scheduler using jQuery (UI), Haml, and Rails. I'm
I am using Postgres 9.1, Rails 3.1.3 and Ruby 1.9.3. I tried some things
I'm using the following in rails to push to node.js: NodePush[].trigger('unit', 'join', {:id =>record.user_id,
I'm using: Rails 3.0.9 Activerecord-sqlserver-adapter 3.0.15 TinyTds MSSQL 2005 I have following table: CREATE

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.