在模型中,我有:如何將關聯加載到實例變量中?
class CalendarItem < Resource
belongs_to :schedule
has_many :people
has_many :documents
acts_as_list scope: :schedule, column: :visual_position
validates :schedule, :title, presence: true
end
然後在控制器:
class ScheduleController < ApplicationController
def show
@calendar_items = CalendarItem.where(schedule: @schedule).includes(:people, :documents)
end
...
end
在我的渲染與反應護欄一react_component的觀點(但應該有任何區別):
= react_component('CalendarItemsList', calendar_items: @calendar_items)
但是它並沒有將關聯的數據傳遞給視圖(react_component),只有主模型。
我以前經歷過這個,沒有反應的前端,也沒有工作。什麼可能是錯的?
它傳遞一個空數組,是否或拋出一個錯誤? –
我可以使用@caledar_items,但它不包含關聯人員和文檔。謝謝 – Aurimas
哦,那應該很容易。試試'CalendarItem.includes().where()'。你有訂單落後。 –