Cross posting to the couchdb-user list.

On Fri, Nov 14, 2008 at 6:09 AM, Sebastian Deutsch
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> the order of attributes in a hash seems not to be safe, evidently that it is
> not a show stopper - but I want to let you know:
>
> @the_template = Template.get(params[:id])
> @the_template.inspect
>
> gives me:
>
> {"schema"=>{"about"=>"Text", "first_name"=>"String", "last_name"=>"String",
> "password"=>"String", "email"=>"String"}, "title"=>"user",
> "_id"=>"f00563d259bfffffbbaaa8d2469315e3", "_rev"=>"1232453443",
> "couchrest-type"=>"Template"}
>
> http://localhost:5984/resttest/f00563d259bfffffbbaaa8d2469315e3
>
> gives me:
>
> {"_id":"f00563d259bfffffbbaaa8d2469315e3","_rev":"1232453443","schema":{"first_name":"String","password":"String","last_name":"String","email":"String","about":"Text"},"title":"user","couchrest-type":"Template"}
>
> if you take a close look at the schema hash, the first attribute in ruby
> will be about, couchdb/utils will give me first_name.
>
> Is it a ruby specific problem?
>

Yes and no. There is no guarantee in the JSON spec nor in ECMAScript
that hash order will be preserved. It just so happens that CouchDB
preserves hash order but that should not be relied upon. Ruby
certainly does not preserve hash order.


-- 
Chris Anderson
http://jchris.mfdz.com

Reply via email to