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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Jan-15 22:51 UTC
Re: 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.Look into single table inheritence... http://www.juixe.com/techknow/index.php/2006/06/03/rails-single-table-inheritance/ Then you''re Lead model could have_one :property_state and have_one :contact_state and all would be well with the world :) -philip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---