Skip to content

Indifferent access for array of hashes #6

@23tux

Description

@23tux

Hi,

I have the following model:

class Run
  include Mongoid::Document
  include Mongoid::Extensions::Hash::IndifferentAccess

  field :results, type: Array, default: []
end

I'm storing hashes inside the :results array. Is it possible to have indifferent access here? For example, when I try to

Run.create! results: [{foo: "bar"}]
Run.first.results.first[:foo] # is nil, doesn't work
Run.first.results.first["foo"] # is "bar", works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions