Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclass does not read the file. #216

Open
1060ki opened this issue Oct 30, 2020 · 0 comments
Open

Subclass does not read the file. #216

1060ki opened this issue Oct 30, 2020 · 0 comments

Comments

@1060ki
Copy link

1060ki commented Oct 30, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant