Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Modify toHash to always return on object of arrays and support duplicate index columns #136

Open
vikeen opened this issue Jun 19, 2015 · 0 comments

Comments

@vikeen
Copy link

vikeen commented Jun 19, 2015

Currently toHash() assumes the column being indexed to be unique.

myModel.toHash("some_unique_key");

However, if the column being indexed is not actually unique you will have an undesired effect of the method overriding your data output

Take this data set for example.

name gender
Bob M
Stan M
Rachel F
Julia F
Fred M

Now when you run your data request

person.toHash("gender");

You will get back an object looking something like the following

{
  "M": { "name": "Fred", "gender": "M" },
  "F": { "name": "Julia", "gender": "F" }
}

This happens because the toHash method is overriding the index key in the return type after each iteration. I would propose that we make this consistent and instead return a grouped data set result.

{
  "M": [
    { "name": "Bob", "gender": "M" }
    { "name": "Stan", "gender": "M" }
    { "name": "Fred", "gender": "M" }
  ],
  "F": [
    { "name": "Rachel", "gender": "F" }
    { "name": "Julia", "gender": "F" }
  ]
}
@vikeen vikeen self-assigned this Jun 19, 2015
@vikeen vikeen added this to the 1.0.0 - node 12 upgrade milestone Jun 19, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant