Question

I need to implement a Week availability/schedule like this one on my App. Each User has his own week availabities :

Week schedule

I need to query my database and be able to find users who are available on specificics slots. I tought I could implement 7x7 = 49 booleans attributes directly on my model , but I feel that it is not a very clean solution!

Other problem I'm facing : I wish to use Thinking_sphinx gem to index and query this content (and others attributes too) with facets navigation. There was a limit of facets numbers previsoulsy I don't know if it is still true.

Do you think it's better to use 49 boolean attributes or 1 single string attribute containing for exemple "Mo1 Mo2 Mo3 ..... Th1 Th6 Th7 Fr1 .....Su7" ?

Or any other solution ?

Was it helpful?

Solution

The first thing to note is that string attributes (as opposed to fields) can't be used in filters, and you'd want single string values for facets (not everything together in a single string), so I don't think your single string attribute suggestion will work out.

An alternative is search on the items in the schedule, get the user ids from that set, and then search across users not in that collection of user ids. It does mean two queries instead of one, but it's a little more obvious and a little less complex.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top