2

I'm having an event-model that has a status attribute, and wonder if I should make it into a string or integer field. The event can have three different statuses, "gathering", "active" or "closed". If I should go with the integer solution, should I define a constant somewhere making it possible to just use CLOSED insted of "2" (and where should I put this constant??)

Thanks in advance!

1 Answer 1

5

I would recommend using an integer for two main reasons.

  1. Most databases can query and index integer columns faster than strings.
  2. It takes up less space on disk, and over the network when querying large data sets.

Weather you choose strings or integers, you should define them as constants and reference them only through their constants. You should never use the values directly.

http://en.wikipedia.org/wiki/Magic_string_(programming)

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

2 Comments

Where should I define them to make them available everywhere (controllers, views, observers an so on..)?
I'd imagine that this state is stored in the model, define it there. ie. Event::CLOSED.

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.