Using One Lookup Table for Multiple Model Properties

I have a model that has two properties that both come from the same database table.

Let's say I have a "Lead" model. This Lead has both a contact "State" (as in Colorado, Arkansas, etc.) and a "Property State" where the house he's looking to refinance is located. Both of these should obviously be objects of the type "state".

I'm running into trouble trying to put both the property_state_id and state_id in the object. Do I need to create a second model for PropertyState and just point it at the same database table? That seems a little messy when PropertyState and State are both basically State objects.

I hope this is clear (as mud probably).

Thanks in advance.

Justin

I have a model that has two properties that both come from the same database table.

Let's say I have a "Lead" model. This Lead has both a contact "State" (as in Colorado, Arkansas, etc.) and a "Property State" where the house he's looking to refinance is located. Both of these should obviously be objects of the type "state".

I'm running into trouble trying to put both the property_state_id and state_id in the object. Do I need to create a second model for PropertyState and just point it at the same database table? That seems a little messy when PropertyState and State are both basically State objects.

I hope this is clear (as mud probably).

Thanks in advance.

Look into single table inheritence...

Then you're Lead model could have_one :property_state and have_one :contact_state and all would be well with the world :slight_smile:

-philip