0
我很難得到一個belongs_to
協會,以加載它的孩子。我有:我可以添加包含擴展到belongs_to關聯嗎?
class User < ActiveRecord::Base
has_many :campaigns, -> { includes :campaign_shirts, :arts, :selected_campaign_shirt }
belongs_to :selected_campaign, {class_name: "Campaign", inverse_of: :user}, -> { includes :campaign_shirts, :arts, :selected_campaign_shirt }
end
導致:
// GOOD
u.campaigns.first.campaign_shirts.first.to_s
=> "#<CampaignShirt:0x007fc023a9abb0>"
u.campaigns.first.campaign_shirts.first.to_s
=> "#<CampaignShirt:0x007fc023a9abb0>"
// NOT GOOD
u.selected_campaign.campaign_shirts.first.to_s
(queries db)
=> "#<CampaignShirt:0x007fc023d7c630>"
(queries db)
u.selected_campaign.campaign_shirts.first.to_s
=> "#<CampaignShirt:0x007fc01af528a0>"
我是否相抵觸的this issue運行?有沒有辦法實現我想要的,這是能夠參考current_user.selected_campaign
,並有急切加載/凍結current_user.selected_campaign.campaign_shirts.first
等?
這是問題,謝謝。 –