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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:49:17+00:00 2026-05-26T18:49:17+00:00

Is it possible to create an attribute for a class that is an array?

  • 0

Is it possible to create an attribute for a class that is an array? I tried reading this but I didn’t get much out of it. I want to do something like this:

class CreateArches < ActiveRecord::Migration
  def change
    create_table :arches do |t|
      t.string :name
      t.array :thearray
      t.timestamps
    end
  end
end

such that when I call .thearray on an instance of Arch I get an array that I can add new elements to.

ruby-1.9.2-p290 :006 > arc = Arch.new
ruby-1.9.2-p290 :007 > arc.thearray
 => [] 
  • 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-26T18:49:17+00:00Added an answer on May 26, 2026 at 6:49 pm

    While you can use a serialized array as tokland suggested, this is rarely a good idea in a relational database. You have three superior alternatives:

    • If the array holds entity objects, it’s probably better modeled as a has_many relationship.
    • If the array is really just an array of values such as numbers, then you might want to put each value in a separate field and use composed_of.
    • If you’re going to be using a lot of array values that aren’t has_manys, you might want to investigate a DB that actually supports array fields. PostgreSQL does this (and array fields are supported in Rails 4 migrations), but you might want to use either a non-SQL database like MongoDB or object persistence such as MagLev is supposed to provide.

    If you can describe your use case — that is, what data you’ve got in the array — we can try to help figure out what the best course of action is.

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

Sidebar

Related Questions

Attributes are awesome. But is it possible to create a C# attribute class that,
Is it possible to create an attribute that can be initialized with a variable
is it possible to create a custom JSTL tag that accepts a non-string attribute?
I tried to create a custom .NET attribute with the code below but accidentally
Is it possible to create an attribute of type Partylist in Microsoft Dynamics Crm
Is it possible to create a trigger that will not be in a transaction?
I want to be able to create an instance of a parent class X,
I'm not sure if this is possible in Spring MVC 3.0, but I'm trying
I know that it is possible (in theory) to create a new type at
Is there a way to create a custom attribute that will make EF CodeFirst

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.