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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:51:32+00:00 2026-06-05T17:51:32+00:00

I have a simple model like this: class User < ActiveRecord::Base serialize :preferences end

  • 0

I have a simple model like this:

class User < ActiveRecord::Base
  serialize :preferences
end

I want to access the raw value from mysql, not value before serialize. Is it possible?

I know I can use

ActiveRecord::Base.connection.execute("select * from users")

But I want to access from the User model.

  • 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-05T17:51:33+00:00Added an answer on June 5, 2026 at 5:51 pm

    Updated

    Ok, this is what you are looking for:

    User.find(params[:id]).attributes_before_type_cast["preferences"][:value]
    

    This will return the string in its serialized form.

    That is the closest you can get that I can find, it won’t work if you have already gotten the object pulled from the database.

    Sorry for misreading your question. You can use this from the User model too.

    Leaving the old answer up just in case the other way of doing it is helpful to someone.

    Old Answer

    Just to be sure I understand the question, you want the raw data from the table. The data that rails serializes and puts in the database.

    EX. You put in ['site_id','last_update','last_restart'] and you get "---\n- site_id\n- last_update\n- last_restart\n" and it is put in the database and saved. You want to retrieve this: "---\n- site_id\n- last_update\n- last_restart\n" from the database.

    Ok, it took some fanagaling from the database but you can do it like so.

    In a project I have a serialized array call devise_table_preferences that lists the preferences to display in a table in a particular order, like so:

    user.devise_table_preferences = ['site_id','last_update','last_restart']
    

    The serialized view of it is like so:

    "---\n- site_id\n- last_update\n- last_restart\n"
    

    Using your method above, I made a query like so:

    preference = ActiveRecord::Base.connection.execute("SELECT devise_table_preferences FROM users WHERE id = #{@user.id}")
    

    It returns an object in the console like so:

    preference = #<Mysql2::Result:0x007fe4cdf34850> 
    

    Running:

    preference.first[0]
    

    Gave me this:

    "---\n- site_id\n- last_restart\n"
    

    I know its a big work around but it will definitely give you your data in its serialized way. Hope that it helps you out.

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

Sidebar

Related Questions

I have a simple model class Ad < ActiveRecord::Base has_many :ad_items end class AdItem
I have this code in my user model: class User < ActiveRecord::Base attr_accessible :email,
I have a simple model: class Project < ActiveRecord::Base belongs_to :user class User <
I have a simple one-to-many structure like this: class User(db.Model): userEmail = db.StringProperty() class
I have a simple model like this: class Auction(models.Model): name = models.CharField() class Item(models.Model):
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have the following two models, User.. class User < ActiveRecord::Base has_and_belongs_to_many :sites end
I have a simple model like this class UserType( models.Model ) : def __unicode__(
I need some help with this one.... I have this simple model: public class
I have a simple Django model resembling: class Address(models.Model): blah class MemberData(models.Model): user =

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.