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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:07:40+00:00 2026-06-18T09:07:40+00:00

I am trying to map a legacy MySQL database with a fresh DataMapper model.

  • 0

I am trying to map a legacy MySQL database with a fresh DataMapper model.

MySQL schema:

CREATE TABLE IF NOT EXISTS `backer` (
  `backer_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `secret` varchar(16) NOT NULL,
  `email` varchar(255) DEFAULT NULL,
  `status` enum('pending','ready') NOT NULL DEFAULT 'pending',  # relevant bit
  PRIMARY KEY (`backer_id`),
  UNIQUE KEY `backer_id` (`secret`),
  KEY `email` (`email`,`status`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8166 ;

DataMapper model:

class Backer
  include DataMapper::Resource
  storage_names[:default] = "backer"     

  property :id,      Serial, :field => "backer_id"
  property :secret,  String, :field => "secret"
  property :email,   String, :field => "email"
  property :status,  Enum[ :pending, :ready ], :field => "status", :default => "pending"
  has n, :items, :child_key => "backer_id"
end

DataMapper.finalize

With most attributes, I can persist:

b = Backer.first
b.first_name = "Daniel"
b.save!
# Backer.first.first_name == "Daniel"

It persists fine.
But when I do it with an enum:

b = Backer.first
b.status = :pending
b.save!

# b.status == :pending
# Backer.first.status != :pending
# Backer.first.update!(:status => :pending) ... 

Updates/saves to an enum field doesn’t seem to persist it.

SQL looks typically like:

1.9.3p327 :019 > Backer.last.update(:status => :ready)
 ~ (0.000349) SELECT `backer_id`, `secret`, `email`, `status` FROM `backer` ORDER BY `backer_id` DESC LIMIT 1
 ~ (0.000190) UPDATE `backer` SET `status` = 2 WHERE `backer_id` = 8166
 => true

But when I view the object (e.g. Backer.last) then status is not changed.

UPDATE

I’ve verified that the enumerated status field in the MySQL database is being persisted. However, the enumerated status property in the DataMapper class doesn’t reflect this at all (is always nil).

What’s happening 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-06-18T09:07:41+00:00Added an answer on June 18, 2026 at 9:07 am

    Thanks @morbusg: that’s one solution.

    The other one was to change the Enum at my end to a String and that’s worked fine for my purposes.

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

Sidebar

Related Questions

I am trying to map a new domain model to a fixed-schema legacy database
I am trying to map a legacy database here and I'm running into a
I am trying to use NHibernate to map a legacy database which uses a
I am trying to map a TPT inheritance hierarchy on a legacy database (I
I am working with an Oracle legacy database and I am trying to map
I'm currently trying to get (Fluent)NHibernate to map an object to our legacy database
I'm trying to map a table (legacy from the Oracle Forms time) that have
I am trying to map the following table CREATE TABLE Person ( p_id varchar(255)
Trying to map the following schema using the Entity Framework. A Customer can have
I'm trying to map a table, where one of the column is a binary

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.