You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Chris Anderson <jc...@grabb.it> on 2008/11/14 16:51:17 UTC

Re: Order of attributes in CouchDB Records

Cross posting to the couchdb-user list.


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

Re: Order of attributes in CouchDB Records

Posted by "ara.t.howard" <ar...@gmail.com>.
On Nov 14, 2008, at 8:51 AM, Chris Anderson wrote:

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

it does - from 1.9 onwards anyhow...  fyi.

a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama