如何使用 'includes' 选项为多个外连接表呈现 json

How to render json for more than one outer join tables with 'includes' option

我有一个外连接活动记录。我需要为外连接查询显示 json。 这是我写的活跃记录

@recent_details=Property.includes(:space_amenities,:event_suitabilities,:purpose_suitabilities,:venue_categories).where(id: params[:id]) respond_to do |format| format.json { render :json => @recent_details.to_json(include: :venue_categories)} end

在 json 部分,使用 include 选项我只包含一个外部连接 table。我需要在包含选项中包括所有这些 4(:space_amenities,:event_suitabilities,:purpose_suitabilities,:venue_categories) tables。如何在渲染时包含所有这些 json.

感谢任何帮助table。

试试这个:

format.json { render :json => @recent_details.to_json(:include=> [:space_amenities,:event_suitabilities,:purpose_suitabilities,:venue_categories]‌​)}