开发者

How store work days of week in db

I have Shop entity

I need 7 checkboxes to set working days for this 开发者_如何学运维shop on frontend

I'm looking for best solution to store values in db. The easiest method is to keep 7 boolean fields like "monday?" "tuesday?" ... in db

Can you help me? thanks

PS: it should be searchable (ex. i want all shops working today)

Rails 3, Postgresql 8.4


How are you going to use this data? If you need to find by working day(s) of week then do boolean columns as you say. If you don't, store as a string representation such as 'tttttff' (open monday to friday).


Since there's little chance you'll have any kind of useful indexes on it, a bit(7) might be a good candidate depending the type of query you're doing. (And assuming AR supports it.)

Alternatively, boolean fields work - it'll just be a lot more verbose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜