On Oct 27, 3:34 pm, Nels Nelson <[email protected]> wrote:
> I am using Ruby Sequel v3.28.0 with JRuby 1.6.5.
>
> I have a Model class with a many_to_many collection.
>
> I want to serialize instances of this Model class, and that is working
> for me for the most part -- to_xml (Nokogiri) and to_json (JSON Java)
> both work, to_yaml not so much.
>
> However, the many_to_many collection does not get serialized.  This
> makes sense, I suppose.  I haven't done anything special to make this
> happen.
>
> But, that is because I don't know what I am supposed to do, to make
> this happen, or if it is even possible.
>
> Can I do that?
>
> How?
>
> Basically, I'd like to have the collection get printed as part of the
> serialized output, and then be able to read it in, and do a from_xml
> or from_whatever to make those entities also get created in the
> appropriate tables joined by my many_to_many Model definitions.
>
> Does this make sense?  Is what I want to do a reasonable thing to want
> to do?

You probably just need to do something like:

  Foo.many_to_many :bars
  foo = Foo[1]
  foo.to_json(:include=>:bars)

You probably want to be using the json_serializer or xml_serializer
plugins, and reading the documentation for those should be helpful:

http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Plugins/JsonSerializer.html
http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Plugins/XmlSerializer.html

Jeremy

-- 
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