考慮以下兩種模式:Rails 5,如何用關聯表來命名兩個模型?
ChefPosition (Executive, Sous, etc...)
Skills (Creativity, speed, quality)
我正在創建一個定義技能每ChefPosition定義了哪些表。到目前爲止,我有:
ChefPositionSkill (chef_position_id, skill_id)
在Rails 5的世界裏,我是否正確地命名模型?如果是這樣,這將是命名控制器返回每ChefPosition的技能,像正確的做法:
ChefPositionSkillController < ApplicationController
def index
@ChefPositionSkills = Skill.where(:chef_position => params[:chef_position_id]
render json: @ChefPositionSkills, status: status
end
end
這是正確的?智慧表示讚賞!謝謝
如果你建立的has_many通過模型'ChefPositionSkill'該型號的控制器將成爲'ChefPositionSkillsController' –
你推薦哪個?什麼是正確的Rails方式來做到這一點? – AnApprentice
如果你需要@ bkunzi01所說的關聯關係的具體信息(即技能等級或分數),請[has_many through](http://guides.rubyonrails.org/association_basics.html#the-has-many-through -association )。如果它只是一個簡單的關聯(除了它們相關的事實外沒有其他信息),請執行[HABTM關聯](http://guides.rubyonrails.org/association_basics.html#the-has-and-belongs-to -many關聯)。如果它是一個HABTM協會,模型/控制器不是必要的,只需要DB表 –