Reputation:
so I know how to include a specific association:
obj.to_json include: :some_association_name
What I'm trying to figure out is if there's a way to blindly include all associations and not have to list each one individually. I optimistically tried:
obj.to_json include: :all
That didn't work, of course. Does anyone have any ideas?
thanks!
Upvotes: 1
Views: 636
Reputation: 11813
Try this:
obj.to_json(include: obj.class.reflect_on_all_associations.map(&:name))
Upvotes: 6