Forum: Ruby on Rails RoR way to handle 2 situations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ray Wenderlich (Guest)
on 2007-06-26 21:54
I'm new to Ruby on Rails, and was wondering what the preferred method is
of handling the two situations in Ruby on Rails:

1) You are designing a database table for "Event" that has a
"recurrence" field.  This field should be an integer in the set 0, 1, 2
meaning "daily", "weekly", and "monthly" respectively.  Is the preferred
method to link to a lookup table, or to restrict the possible values
somehow?

2) You have designing a database table for "Person" that has an optional
"birthday" field (you might not know the person's birthday).  How can
you indicate whether it is valid or not?  Is the preferred method to add
a "isValid" field, or to have another "Birthday" table that may or may
not be linked in?

Appreciate it!

--RAy
Philip H. (Guest)
on 2007-06-26 22:29
(Received via mailing list)
> 1) You are designing a database table for "Event" that has a
> "recurrence" field.  This field should be an integer in the set 0, 1, 2
> meaning "daily", "weekly", and "monthly" respectively.  Is the preferred
> method to link to a lookup table, or to restrict the possible values
> somehow?

Another way to do it may be to use integer values for 1, 7, and 30, but
then months aren't all 30 days apart :(.  I think the issue of whether
or
not to use a lookup table is if you might have other apps look at the
database and want to get the value.  I suspect I'd go with the lookup
table just to keep it all consistent (in the db).

> 2) You have designing a database table for "Person" that has an optional
> "birthday" field (you might not know the person's birthday).  How can
> you indicate whether it is valid or not?  Is the preferred method to add
> a "isValid" field, or to have another "Birthday" table that may or may
> not be linked in?

If birthday is NULL then it's invalid/unknown.  Otherwise that is their
birthday.  Also, I'd suggest using their birth *date* so you can
calculate
how old they are as well.  Perhaps "born_on".

-philip
This topic is locked and can not be replied to.