Relational tables - dependent => :update?

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?

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

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.