
to_xml for collections - Model.first.to_xml works but Model.all.to_xml doesn't.
Reported by Daniel Parker | February 22nd, 2008 @ 12:04 PM
It could be argued that defining to_xml for Arrays should be someone else's problem, but my opinion is that it would honor consistency to make this work.
The problem is quite simple: Given a datamapper model, Model, I can do Model.first.to_xml and it will give me xml. But I can't do Model.all.to_xml, which should be possible.
My suggestion is to use a collection class just like associations do, instead of a simple Array, when returning lists of datamapper objects. This collection, then, would have methods like to_xml, to_json. It would also be handy if the collection behavior could be applied to an array, or created from an array, for cases where the user may need to collect objects manually into a collection with this behavior.
Comments and changes to this ticket
-
Sam Smoot March 17th, 2008 @ 10:23 AM
- State changed from new to open
Good idea. We were probably going to switch to using a custom collection anyways for other reasons, this adds another good justification for the move.
-
Sam Smoot March 17th, 2008 @ 10:28 AM
- Milestone cleared.
-
Daniel Parker March 17th, 2008 @ 10:41 AM
I wrote this functionality for myself, and if it's any help, I've pastie'd it: http://pastie.caboo.se/166791
The main idea revolves around having a collection object with the rule that only the same class of objects can exist in the collection.
Currently that's working great for me. Perhaps something could be gleaned from it.
-
Sam Smoot April 27th, 2008 @ 10:24 PM
- Assigned user set to Guy van den Berg (guyvdb)
Guy? I thought you had done some work on this?
-
Guy van den Berg (guyvdb) April 28th, 2008 @ 01:42 AM
Sam, I have done some work on basic serialization which is committed. I am working on advanced serialization which includes contexts and schemas. This will allow for Zoo.all().to_xml - but I am not there yet.
-
Sam Smoot June 2nd, 2008 @ 04:57 PM
- Milestone cleared.
-
Dan Kubb (dkubb) November 30th, 2008 @ 06:43 PM
- Tag set to suggestion
- Milestone cleared.
- Assigned user changed from Guy van den Berg (guyvdb) to Xavier Shay
Xavier, I know you did some recent work on dm-serializer, so I just wanted to follow up with you on the #to_xml and #to_json related tickets. Do you know if this ticket still applies?
-
Xavier Shay November 30th, 2008 @ 06:49 PM
- Tag changed from suggestion to dm-more, dm-serializer
I think this is fixed, but I will confirm
-
Xavier Shay December 1st, 2008 @ 03:12 PM
- State changed from open to resolved
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Tags
Referenced by
-
419 to_xml does not create xml compatible with ActiveResource I've added some specs + fixes for this. It also starts t...