-
Notifications
You must be signed in to change notification settings - Fork 57
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
undefined method 'accessor' for ActiveRecord::Type::Value #33
Comments
That's strange. Decimals are part of the test suite :/ I'll see what I can do, but a reproduction gist would tremendously help. You could base it off Rails's repro template: https://github.com/rails/rails/blob/adfb823af52d368fa4d88731a9809a314ad884ad/guides/bug_report_templates/active_record_gem.rb |
@byroot Here you are. This perfectly reproduces my real problem.
This is my output:
|
t.text :data
|
@byroot Reproduced more thoroughly. Seems like it's because of delegate.
|
Oh! I see. You can't define a store on something that isn't a real attribute. TypedStore need to read the column information from ActiveRecord. If you really wish to delegate this column, you can still do it this way: begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.2.4'
gem 'sqlite3'
gem 'byebug'
gem 'activerecord-typedstore', '0.6.1'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
t.integer :author_id
t.text :data
end
create_table :authors, force: true do |t|
end
end
class Post < ActiveRecord::Base
belongs_to :author
typed_store :data do |s|
s.decimal :value
end
end
class Author < ActiveRecord::Base
has_one :post
delegate :value, :value=, to: :bound_post
def bound_post
@bound_post ||= build_post
end
end
class BugTest < Minitest::Test
def test_association_stuff
Author.create!(value: 36.6)
assert_equal 1, Author.count
end
end |
Exactly, this is my current workaround. But this only works when your bound model class and parent class is one to one. |
Think for normal situations that is not a bug. |
Rails 4.2.4, activerecord-typedstore 0.6.1. When I try to instanciate record with decimal typed value described. I get this:
The text was updated successfully, but these errors were encountered: