我有一个rails应用程序,我有以下模型。rails包含查询加载包含模型的全部数据
BookingHotel
has_many :hotel_picture_partners, through: :hotel_pictures
has_many :booking_hotel_partner_details, dependent: :destroy
BookingHotelPartnerDetail
belongs_to :booking_hotel
HotelPicturePartner
belongs_to :hotel_picture, dependent: :destroy
我有一个查询如下
@booking_hotel_partner_details = BookingHotelPartnerDetail.unscoped.select(:id, :booking_hotel_id, :partner_booking_hotel_id).includes(booking_hotel: :hotel_picture_partners)
,因为它为加载模型包含的所有数据这使得在压力下的记忆。
有没有办法只能从booking_hotels加载选择字段& hotel_picture_partners表?
另外我想获得一个activerecord数组作为响应。
的可能的复制[Rails 3中 - 选择具有包括哪些?(http://stackoverflow.com/questions/4047833/rails-3-select-with-include ) –