couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <jch...@grabb.it>
Subject Re: Order of attributes in CouchDB Records
Date Fri, 14 Nov 2008 15:51:17 GMT
Cross posting to the couchdb-user list.


On Fri, Nov 14, 2008 at 6:09 AM, Sebastian Deutsch
<sebastian.deutsch@gmail.com> 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

Mime
View raw message