Having customer and category table. There are category1_id and category2_id in customer table. If having @customer, how to fetch the category name by given @customer and linking the category1_id and category2_id with the id in category table?
customer schema:
create_table "customers", :force => true do |t|
t.string "name"
t.string "short_name"
t.string "contact"
t.string "address"
t.string "country"
t.string "phone"
t.string "fax"
t.string "email"
t.string "cell"
t.integer "sales_id"
t.string "web"
t.integer "category1_id"
t.integer "category2_id"
t.boolean "active", :default => true
t.string "biz_status"
t.integer "input_by_id"
t.string "quality_system"
t.string "employee_num"
t.string "revenue"
t.text "note"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
category schema:
create_table "categories", :force => true do |t|
t.string "name"
t.string "description"
t.boolean "active", :default => true
t.datetime "created_at"
t.datetime "updated_at"
end
In routes.rb file
resources :customers do
resources :categories
end
Given @customer, how to fetch category name, like @cusotmer(category1_id).category.name?
Thanks.