active-hash / active-hash/active_hash

Remove 'attributes' nesting?

Open
#204 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.4k
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Hi,
I have a class extending ActiveYaml::Base as below:

class Item < ActiveYaml::Base
  set_root_path Rails.root.join('db', 'static')
  field :name
end
# items.yml
- id: 1
  name: Animal Welfare
- id: 2
  name: Climate Change
- id: 3
  name: Asylum Seekers

However when I query the data, it always comes back nested under an attributes key.

irb(main):020:0> Item.all.as_json
=> [{"attributes"=>{"id"=>1, "name"=>"Animal Welfare"}}, {"attributes"=>{"id"=>2, "name"=>"Climate Change"}}, {"attributes"=>{"id"=>3, "name"=>"Asylum Seekers"}}]

irb(main):023:0> Item.first.as_json
=> {"attributes"=>{"id"=>1, "name"=>"Animal Welfare"}}

Is there a reason why this has to be the case, or can I remove it somehow? It's a bit annoying because I'll eventually want to start using ActiveRecord, and then we'll have to update the client to stop looking for that key or else start adding it in to the DB records.
Thanks

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the ActiveYaml::Base Item example and the items.yml data shown in the issue, then inspect how Item.all.as_json and Item.first.as_json produce the attributes wrapper. Confirm whether removing that nesting is intended and whether existing ActiveHash serialization behavior depends on it; done means the requested JSON shape is clear and verified without breaking current behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.