hi. simple question. i have a table that contains a town_id column. is
there a way to get what town name it is from a town_id? my table
‘profiles’ belongs_to table ‘town’, and town has_many profiles. or do i
just execute a find_by_sql on town_id number and use the string name it
returns?
hi. simple question. i have a table that contains a town_id column. is
there a way to get what town name it is from a town_id? my table
‘profiles’ belongs_to table ‘town’, and town has_many profiles. or do i
just execute a find_by_sql on town_id number and use the string name it
returns?
i tried it but its a no go. i also tried appending id2name, to_s, and
to_i but no avail. i even just tried printing out the town_id but that
also doesnt work?!
basically my
@profile = Profiles.get_details
where get_details returns hash of all columns for the profile from the
Profiles table
profile should contain all the columns in the profile table, this
includes town_id which belongs to town table
but when i try printing out town_id with this line
logger.debug @profiles[0][‘doctype_id’]
, i get ‘String can’t be coerced into Fixnum’
Al Evans wrote:
koloa wrote:
hi. simple question. i have a table that contains a town_id column. is
there a way to get what town name it is from a town_id? my table
‘profiles’ belongs_to table ‘town’, and town has_many profiles. or do i
just execute a find_by_sql on town_id number and use the string name it
returns?
@profiles[0][‘doctype_id’].to_s it prints the id number, now i am
working out trying to see if i can translate the id to the actual name
that the id matches to…
where get_details returns hash of all columns for the profile from the
Profiles table
Out of interest - why are you doing this instead of using the fields
provided by ActiveRecord? The idea behind AR is that you can do
Profiles.find(:all) and then for each profile use profile.name or even
traverse relationships like profile.town.name.
hello,
basically i have a search process that displays all doctors available in
a given town. when the user clicks on a doctors name, i just wanted to
display the doctors town/county from where his/her office is located.
after sometime, i think i just will kepp that information seperate.
Max M. wrote:
basically my
@profile = Profiles.get_details
where get_details returns hash of all columns for the profile from the
Profiles table
Out of interest - why are you doing this instead of using the fields
provided by ActiveRecord? The idea behind AR is that you can do
Profiles.find(:all) and then for each profile use profile.name or even
traverse relationships like profile.town.name.