Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-782

Unable to specify :include option in to_json for collection of model

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.0.2
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      I was trying to specify the :include option to the to_json Document methods in order to include model associations in the generated json, but it turns out that it is not possible to do that on a collection, only when dealing with a single model instance.
      Example:
      MyModel.all.entries.to_json :include => :myrelationship

      This ends up not including "myrelationship" in the generated json code at all. However, this works in this case:
      MyModel.first.to_json :include => :myrelationship

      Tested with mongoid 2.0.0 rc6

            Assignee:
            Unassigned Unassigned
            Reporter:
            felipecsl Felipe Lima
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: