I am applying Rails to an existing schema and not sure how much the
existing developers will let me go in and rename things. So I need to
discover the limits of what I can change with Rails.
I’ve found set_table_name and set_primary_key, which have been very
useful.
If I have a “foo has_one :bar” relationship, but then in the bar table
my column is named “fooid” or some other thing that is not “foo_id”, is
there a similar helper command I can use to change it? Everything’s
working swimmingly for me, except when I get to this bit and it errors
out telling me “cannot find bar.foo_id” and I can’t figure out a way to
point to bar.fooid and say “There it is.”
I tried googling around for “set foreign key constraint column name” but
can’t seem to track anything down.
I am applying Rails to an existing schema and not sure how much the
existing developers will let me go in and rename things. So I need to
discover the limits of what I can change with Rails.
I’ve found set_table_name and set_primary_key, which have been very
useful.
If I have a “foo has_one :bar” relationship, but then in the bar table
my column is named “fooid” or some other thing that is not “foo_id”, is
there a similar helper command I can use to change it? Everything’s
working swimmingly for me, except when I get to this bit and it errors
out telling me “cannot find bar.foo_id” and I can’t figure out a way to
point to bar.fooid and say “There it is.”
I tried googling around for “set foreign key constraint column name” but
can’t seem to track anything down.
Thanks!
Look for the docs for has_one
There is a :foreign_key option there
Thanks everybody, sorry for the RTFM. I was going through “Agile Web
Development with Rails” and glanced right over it because that option
was discussed as part of belongs_to, not has_to. That’s what I get for
speedskimming.
I knew it had to be an easy answer :).
d
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.