← Back to Upcase

Help in going either STI or Polymorphic


(Roneesh Vashisht) #1

Hi all,

I have a bit of a conundrum I’d appreciate feedback on.

I have a model in my rails app called guest, when a real life user checks into a place, it creates a row in the guest table.

Right now our system logs four guest types: Tour, Event, Information, Meeting.

Tour, Even and Information are all the same, they just collect a name, email and then fill in a column in the db called “event_type”, with a string of either “tour”, “event” or “information”

The outlier is Meeting, because meeting requires an employee_id field to do it’s job properly (it sends a text to the employee in the office, notifying them their guest has arrived).

This requires the Guest table to have a employee_id column that for many guest records is nil.

What’s the best way to handle this Meeting type of Guest?

Since it’s just one column with empty data, would STI be ok? Or do you all prefer to not even have one potentially empty column and go Polymorphic?

I would have just went polymorphic with all meeting types, except that I’m not clear if over time they’ll evolve to be really different things. Right now it’s just more of a contextual tag to explain why someone is here. The separate guest types don’t behave different, with the exception of a meeting guest type, which sends a notification. Eventually maybe tour and event will utilize lists of tour and even types, but that’s potentially months of customer validation down the line.

Any feedback would be appreciated! Even just a quick “do this #{method}”

-Roneesh