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 | in 1.x
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 changed from to 0.9.0
-
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 changed from 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 changed from 0.9.0 to 1.x
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
