如何在 api_controller 中包含其他数据
how to include another data in api_controller
我有这个代码:
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
,因为在 table 咨询公司我有一个 sender_id 并且我必须打印 full_name 而不是 id
我该怎么办?
您可以包括 multiple associations:
render json: @consultancy.to_json(include: [:profiles, :sender])
我有这个代码:
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
,因为在 table 咨询公司我有一个 sender_id 并且我必须打印 full_name 而不是 id
我该怎么办?
您可以包括 multiple associations:
render json: @consultancy.to_json(include: [:profiles, :sender])