Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.
This repository was 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

@vikeen

Description

@vikeen

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" }
  ]
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions