comments = Song.find(65).comments.select('comments.*, users.*').includes(:user).limit(20)
ユーザーを結果セットに含めるにはどうすればよいですか?
私はPusherAppを使用して、やろうとしています:
Pusher["foo"].trigger("bar", {
:comments => comments
})
comments = Song.find(65).comments.select('comments.*, users.*').includes(:user).limit(20)
ユーザーを結果セットに含めるにはどうすればよいですか?
私はPusherAppを使用して、やろうとしています:
Pusher["foo"].trigger("bar", {
:comments => comments
})
カスタムフィールドを使用してjsonを非常に高速に生成する場合は、このチュートリアルをお読みください。
基本的に次のような方法を使用します。
def self.lightning
connection.select_all(select([:latitude, :longitude, :timestamp, :virtual_odometer]).arel).each do |attrs|
attrs.each_key do |attr|
attrs[attr] = type_cast_attribute(attr, attrs)
end
end
end
これにより、ハッシュの配列が返されます。
次にrender json: Oj.dump(@statuses.lightning, mode: :compat)
、ojgemでを使用します。
includes(:user) を joins(:user) に置き換えると、ユーザーフィールドを選択できるようになります
comments = Song.find(65).comments.select('comments.*, users.*').joins(:user).limit(20)