sesc360
sesc360

Reputation: 3255

Database model for status property

When I create a model for a ticket I want to save in a database, and this ticket has a property "status", how should setting this value be reflected properly in the database?

I would think of creating two tables, with Table 1: Tickets and Table 2: Ticket_Status. As an example it could look like:

Tickets: id, status, message

Ticket_status: id, status

I think it would be a ManyToMany relationship and I therefore would need a pivot table? So would this be the right approach, instead of saving the status directly in the ticket entry, I would save the different types in this separate table and use the ManyToMany relationship via pivottable?

Thanks

Upvotes: 1

Views: 332

Answers (1)

Itipacs
Itipacs

Reputation: 182

If you want a history of the status you have to use a ManyToMany relationship and a pivot table.

If only want to show the actual status make a unique table

Tickets: id, status, message

Its a good practice if you at least in database have and history of the status changes. (First Option)

Upvotes: 1

Related Questions