josevalim/active_model_serializers — pull request #97 by twinturbo (2012-07-16 12:23:33+00:00)
Title: Raise error when associations cannot be included

include! only works when the source serializer has a root set. The as_json method sets up some state for the include! method. If a child association has associations with `:include => true` or `root foo, :include => true` would cause an undefined method error for `NilClass`. This is entirely unhelpful for the end user.

This commit raise an error when this situation occurs. It makes it clear that it's not a problem with AMS but the serialization graph.

TL;DR: You can't include associations on a child serializer when the parent doesn't. Raise an error when this situation happens.