Skip to content

Subclass does not read the file. #216

@1060ki

Description

@1060ki

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions