8

I want to have a Status model which will be relatively static after some user-defined set up (and different users may have different values on status).

The status can apply to different models, such as Contact and Event.

so the statuses returned by contact.status will be different from event.status

I want to design the app so that status table has different types (contacts and events).

What is the right strategy and format for this?

I am thinking of declaring :has_one Status in the Contact model, and storing a :status_id in the :contacts table. Ditto with Event.

:statuses table will have the status value, type, and date.

does this make sense? Can you suggest a better approach?

aceofbassgreg
  • 3,837
  • 2
  • 32
  • 42
Satchel
  • 16,414
  • 23
  • 106
  • 192

3 Answers3

9

There is a guide on this very question. Your situation is slightly different in that it seems as though your Status model really needs to be polymorphic since different things will be 'statusable'.

To answer your question, Contact/Event has_one Status does make sense to me.

theIV
  • 25,434
  • 5
  • 54
  • 58
  • 1
    my status model is polymorphic....I edited it above....I'm wondering whether I should make things simple since it seems to be hard to search on it...harder than I thought – Satchel Jul 11 '10 at 02:24
2

Just to complete the answer in a more general setting, that can drive your choice : belongs_to association is used in the model that has the foreign key.

Arun Kumar Mohan
  • 11,517
  • 3
  • 23
  • 44
epsilones
  • 11,279
  • 21
  • 61
  • 85
1

Firstly, the has_one relationship does not store an id in the current model. It looks for a foreign key in the relative table. In order to store a status_id in Contacts or Events you'd use belongs_to.

Secondly, depending on the type of information you're storing in Status, why does it need to be its own separate table? Why not make a status column in each model you want to use status on? A little more information may be useful here.

nuclearsandwich
  • 455
  • 5
  • 9
  • 1
    Well...it could be. It seemed that I've seen ERD's set up where certain attributes that were pretty standardized tended to be separate tables. Since as I noted above the status values do not change much, it seemed like that would be the sort of thing in its own table, especially since it will be made available as a drop-down or auto-complete as an attribute. – Satchel Jul 10 '10 at 23:10