I have one stupid question.
I have 2 tables in DB, and in one table (example: report) I have foreign key from table “warehouse”. I want to get the name of warehouse in my report.
I used this method to find something from other table:
@report = ReportMain.find(params[:id])
@warehouse = Warehouse.find(@report.warehouse_id).name
My question is, there is some simplest way to do this?
Depending on the relation between these tables:
Would work if a Warehouse
belongs_toto a Report, and a Reporthas_oneorhas_manyWarehouse. Be sure to check out the Association Basics in the Ruby on Rails guides, it’s an awesome read.