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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:28:04+00:00 2026-05-27T19:28:04+00:00

I have code which is updating a model’s property then calling save! . A

  • 0

I have code which is updating a model’s property then calling save!. A Rails.logger.info call shows that the model thinks it has the new values. But the SQL write performed by the save! call is writing the old value to the database.

At first it wasn’t writing anything to the database at all when I called save!. I thought it was that the object wasn’t thinking its value had changed for some reason: changed? returned false, so I used a _will_change! notification to force a write. But now it is doing a write, but with the old values.

This doesn’t happen from the “rails console” command line: there I’m able to update the property and it will return changed? of true, and let me save successfully.

Excerpt from the server log follows. Note that the object thinks it has log_ids of ‘1234,5678,1137’, but writes to the database ‘1234,5678’.

current log ids are [1234, 5678]
new log ids are [1234, 5678, 1137]; writing log_ids of ‘1234,5678,1137’ to NewsList 13 with dirty true
SQL (2.0ms) UPDATE “news_lists” SET “log_ids” = ‘1234,5678’, “updated_at” = ‘2012-01-02 02:12:17.612283’ WHERE (“news_lists”.”id” = 13)

The object property in question is log_ids, which is a string containing several IDs of another kind of object.

The source code that produced the output above:

def add_log(new_log)
  new_ids = get_log_ids
  Rails.logger.info("current log ids are #{new_ids}")
  if new_ids.length >= NewsList.MAX_LENGTH
    new_ids.shift
  end
  log_ids_will_change!
  new_ids.push new_log.id
  log_ids = new_ids.join ","
  Rails.logger.info("new log ids are #{new_ids}; writing log_ids of '#{log_ids}' to NewsList #{id} with dirty #{changed?}")
  save!
end
def get_log_ids
  if log_ids 
    log_ids.split(",").map &:to_i 
  else
    []
  end
end

Can anyone suggest what might be going on here?

  • 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-05-27T19:28:04+00:00Added an answer on May 27, 2026 at 7:28 pm

    Add the self to self.log_ids = new_ids.join "," otherwise you will just be assigning to the local variable (namesake) instead of the db-persisted attribute (column).

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

Sidebar

Related Questions

I have a problem with updating the value of property from code which is
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have a backbone model which contains an array which I am updating with
I have a ViewController class that has a property that is the model which
I have code which needs to do something like this There is a list
I have code which as been working against an older Active Directory server and
I already have code which lazy loads scripts on request. My issue now is
I have some code which collects points (consed integers) from a loop which looks
I have have some code which adds new cells to a table and fills
I have some code which utilizes parameterized queries to prevent against injection, but I

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.