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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:34:52+00:00 2026-06-17T00:34:52+00:00

I recently wanted to write a simple migration script. I wrote: @entries = Entries.all(:text

  • 0

I recently wanted to write a simple migration script. I wrote:

@entries = Entries.all(:text => /test/)

@entries.each do |entry|
  entry.update(:text => entry.text.gsub!(/test/, "no-test"))
end

It didn’t save the records, even though the update statement returned true. What did I miss?

  • 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-17T00:34:53+00:00Added an answer on June 17, 2026 at 12:34 am

    In the 1.x series of datamapper the dirty tracking is done via calling #== on the new and old attribute values to detect dirtyness. If an object is mutated inplace (for example with the String bang methods), the change cannot be detected as the “orignal” state gets mutated also.

    Basically the following happens internally:

    a = "foo"
    b = a.gsub!("foo", "bar")
    a == b     # => true both a and b refer to the same mutated object
    a.equal?(b) # => true
    

    In your example you assign the original mutated attribute back to the object, no identity change => no update detected.

    In case you create a new object via String#gsub istead of mutating the original attribute value via String#gsub! you end up with a detectable change.

    With assigning a new object with different value the following happens:

    a = "foo"
    b = a.gsub("foo", "bar")
    a == b      # => false, loaded state does not equal resource state so change is detected
    a.equal?(b) # => false
    

    And for having all cases covered, assigning a new object with same value:

    a = "foo"
    b = "foo"
    a == b      # => true, no dirtyness detected.
    a.equal?(b) # => false
    

    Hopefully this explains the semantic differences good enough to explain all similar cases.

    BTW In datamapper 2.0 we have a differend mechanism that will also catch in place mutations. Disclaimer, I’m the author of this component called dm-session.

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

Sidebar

Related Questions

My wife recently bought a nano, and I wanted to write a simple program
I wanted to list all my Recently Used Items. I use this code: public
Just a quick one - I wrote a php script recently that dynamically creates
I've started learning Lisp recently and wanted to write a program which uses gtk
I am creating a game. I have some UI with text. Recently we wanted
I recently had this question in an interview to write test cases to test
I recently wanted to test my application on another computer that has the latest
I've recently discovered the CTP Async Library and I wanted to try to write
I was recently asked to write 3 test programs for a job. They would
I recently wanted to see if I am able to solve an easy sudoku

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.