我有這個代碼:
module Api::V1
class ConsultanciesApiController < Api::V1::ApiController
before_action :set_consultancy, only: [:show]
def show
render json: @consultancy.to_json(include: [:profiles])
end
private
def set_consultancy
@consultancy = Consultancy.find(params[:consultancy_id])
end
end
end
我必須包括在內:sender,因為在表格咨詢中我有一個 sender_id 并且我必須列印 full_name 而不是 id 我該怎么辦?
uj5u.com熱心網友回復:
您可以包含多個關聯:
render json: @consultancy.to_json(include: [:profiles, :sender])
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/426748.html
