0

I have a bunch of check boxes which represent each day of the week... The user can check one or more days of the week. How should I store it in my database? A field with "days" and a numerical representation of each day? so if they check monday and it tuesday it would store 12? I'm not sure what the most optimal way of doing this is. Thanks.

1
  • days as in monday-sunday? or like dates? Commented Mar 6, 2012 at 9:55

2 Answers 2

1

If you don't need do some search on it, you can use the serialize method to serialize in Array your output. You can do like that

serialize :days, Array

With this configuration, the day are save like a String in your database. This string is a Yaml representation of your Array. So when you get days from your model. You have an Array like result.

Sign up to request clarification or add additional context in comments.

1 Comment

I need to perform searches on it
0

I recommend to read http://en.wikipedia.org/wiki/Database_normalization.

Personally, I'd store it with a datetime field and a user_id field. That's it. This my produce more data, but extending it with searches etc is easier.

2 Comments

wouldn't this take up more space in the database if there's a lot of data?
Yup. But since databases are built to store data, even a lot of data, this usually is no problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.