active-hash / active-hash/active_hash

Subclass does not read the file.

Open
#216 0 comments 1 reaction 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

The record is not set correctly in the following situations.(I think this case rarely happens)

books.yml

- id: 1
  name: Book1

Sample code

require 'bundler/inline'
gemfile do
  source 'https://rubygems.org'

  gem 'active_hash'
end


class Book < ActiveYaml::Base
end

class SubBook < Book
  set_filename 'books'
end

# Book.count should be 1, and it will be 1.
puts "Book.count => #{Book.count}"

# SubBook.count should be 1, but it will be 0.
puts "SubBook.count => #{SubBook.count}"

# Set data_loaded to false
SubBook.data_loaded = false
# SubBook.count will be 1
puts "SubBook.count => #{SubBook.count}"

I think the solution to this problem is to change data_loaded from class_attributes to class instance variable. What do you think?

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

Start with the books.yml fixture and the sample Ruby code showing Book and SubBook inheritance, set_filename, data_loaded, and count. Trace how ActiveYaml::Base loads records for the subclass, then verify that both SubBook.count calls return 1 without manually resetting data_loaded.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.