I have two classes 'Company' and 'CompanyType' Company has_one :company_type and CompanyType belongs_to :company My company_type table contains a field called "ctype" - when I modify this, I'd like all companies of that type to update to the new modified name. Is there a way to do this with dependencies, or would anyone be kind enough to suggest another way?
on 2005-11-30 21:44
on 2005-12-01 17:41
I think you have the relationships reversed. If a company can be one of many different types, your relationships should be: Company belongs_to :company_type, :foreign_key => 'ctype_id' CompanyType has_many :companies and your tables should be: Company id ... ctype_id Company_Types id ctype ... Now you may change the value for ctype in the Company Types table and the changes will be reflected in all the companies that reference that company type. eg mycompany.ctype.ctype Hammed
on 2005-12-01 18:01
hammed wrote: > I think you have the relationships reversed. You were right! Absolutely fantastic - thanks ever so much for your help. I'm still getting to grips with RoR and table relationships. Many thanks again.