Select specific columns with active loading

I am on Rails 2.3.5 and am trying to figure out the syntax to select in some columns with a look for loading. For instance,

class Organizer < ActiveRecord::Base
 has_many :events
end

class Event < ActiveRecord::Base
 belongs_to :organizer
 has_many :bookings
end

class Booking < ActiveRecord::Base
 belongs_to :event
end

Say, in the Show OrganizerController method, I want to use loading to grab specific columns from the Organizer, Event, and Booking models. I believe that here is a code that captures all columns from all three models

Organizer.find(params[:id], :include => {:event => {:booking}})

But let me say that I only want to capture organizer.id, event.id and booking.id, what is this syntax?

+3
source share
1 answer

Found the answer in this article.

Use: just like that, for example,

david.to_json(:include => { :posts => { 
                            :include => { :comments => { 
                                          :only => :body } }, 
                            :only => :title } })
0
source

Source: https://habr.com/ru/post/1774877/


All Articles