Working on this some more, it appears that I didn't include
the :json_serializer plugin in Datapoint, which is why I got default
Datapoint.to_s in the datapoints collection.

I also realized that the depth of the tree must be specified in the
to_json method or in the :json_serializer. Sequel won't figure out the
arbitrary nesting for you. Check out this pastie for a simple example
of deeply nested vs. not-so-deeply nested JSON-ification: 
http://pastie.org/1215548

On Oct 11, 10:46 am, Jason Rogers <[email protected]> wrote:
> I've searched around on Google before posting this and didn't found
> anything useful. So, feel free to point me to a URL that answers this
> is you find one.
>
> I have a Category class. Categories have Datapoints and Categories. I
> want to JSON-ify this deeply nested tree structure, but it fails at
> the second level.
>
> Does anyone know how to configure the json_serializer so that it
> traverses past the first depth of associations?
>
> I configured it like this: Category.plugin :json_serializer, :include
> => {:categories => {:include => Category.columns +
> [:datapoints]}, :datapoints => {:include => Datapoint.columns}}
>
> Here's a simple example of one category (classcat_id => 1010138) that
> has a subcategory (classcat_id => 1010140). That subcategory has a
> single datapoint:
>
> [
>   {
>     "json_class": "Category",
>     "class_id": 10010,
>     "class_parent": null,
>     "class_name": "Manual Test Cases",
>     "class_tag": "JWH_TEST_CASE",
>     "classcat_id": 1010138,
>     "classcat_parent": null,
>     "classcat_class": 10010,
>     "classcat_name": "Imported Data",
>     "categories": [
>       {
>         "json_class": "Category",
>         "class_id": 10010,
>         "class_parent": null,
>         "class_name": "Manual Test Cases",
>         "class_tag": "JWH_TEST_CASE",
>         "class_description": null,
>         "class_keywords": null,
>         "class_can_publish": 1,
>         "class_is_active": 1,
>         "classcat_id": 1010140,
>         "classcat_parent": 1010138,
>         "classcat_class": 10010,
>         "classcat_tag": "TEST_IMPORT_CIRC_OUTPUT",
>         "datapoints": [
>           "#<Datapoint:0x6e5cbebb>"
>         ]
>       }
>     ],
>     "datapoints": [ ]
>   }
> ]

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to