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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:31:56+00:00 2026-06-09T21:31:56+00:00

I have a model called Day that represents a day in a timesheet. I’ve

  • 0

I have a model called Day that represents a day in a timesheet. I’ve noticed that whenever I call @day.save it’s writing to the database, even though none of the object’s properties have had their values changed.

@day = Day.last
 => #<Day lunch_minutes: 0, updated_at: "2012-08-19 12:09:40", work_hours: 5.5>

A day has its length in hours, and the length of its lunch break in minutes, stored. I’ve cropped out some properties that aren’t relevant.

@day.lunch_minutes
=> 0
@day.lunch_minutes = 0
 => 0
@day.changes
=> {"lunch_minutes"=>[0, 0]}
@day.lunch_minutes_changed?
 => true

That should be false. Compare to a value that isn’t zero:

@day.work_hours = 5.5
=> 5.5
@day.work_hours_changed?
=> false

So if I call save, this gets called. Ideally there would be no unnecessary database interaction here.

@day.save
(0.5ms)  UPDATE "days" SET "lunch_minutes" = 0, "updated_at" = '2012-08-19 12:22:59.586860' WHERE "days"."id" = 48

I’m not sure if this is a Rails bug or if I’m doing some incorrectly somewhere. It looks like it could be an issue in “changes_from_zero_to_string?” – I think adding a && value != 0 to that method would fix it – but I want to know if anyone else has seen this/a fix for this before?

  • 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-09T21:31:57+00:00Added an answer on June 9, 2026 at 9:31 pm

    What version of rails are you using? I just had a go in my app (3.1.5/1.8.7) and it doesn’t behave this way.. I just used a random integer property on one of my models to test with:

    1.8.7 :006 > o = Order.first
     => <Order id:...>
    1.8.7 :007 > o.order_items_count
     => 0 
    1.8.7 :008 > o.order_items_count = 0
     => 0 
    1.8.7 :009 > o.changes
     => {} 
    1.8.7 :010 > o.order_items_count = '0'
     => "0" 
    1.8.7 :011 > o.changes
     => {} 
    1.8.7 :012 > o.save
       (0.1ms)  BEGIN
       (0.1ms)  COMMIT
     => true 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model called Business , and I want to save Business.all into
I have a model called company that has_many users then users belongs_to company. class
I have a model Rails model called Orders that has a type_id, location, and
I have a model called City. I have several methods that look for a
I have an app called blog that has a model called Entry. I use
In rails 3, I have a database model that has a birthday field, of
I have model/controller called notification. I want to make a new url so that
I have a model called salon that has_many stylists that has_many appointments . I
I have a model called Event and another called Product. An event has many
I have a model called Invoice .I have made necessary CRUD for Invoice model

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.