How to eager load assocations

I have the following associations in my ActiveRecord models

  1. Groups
  2. Users

Each Group has and belongs to many users

There is an api endpoint - /api/v1/groups which returns a list of
the
groups. In the controller when I am sending a list of 20 groups, the
Users
property is not populated beforehand in the json structure. Anyway to
include the Users property in the json response.

Thanks,
Ganesh

You can use Group.includes(:users)

See here more info

On Fri, May 2, 2014 at 2:54 PM, Andrei G. [email protected] wrote:

You can use Group.includes(:users)

​Includes didn’t work. But I asked on IRC and someone suggested using a
custom serializer.

That worked like a charm