byroot / activerecord-typedstore

ActiveRecord::Store but with type definition
MIT License
441 stars 57 forks source link

Deprecation Warning on unknown attribute #59

Closed bryanrite closed 6 years ago

bryanrite commented 6 years ago

Hey! I was testing out this gem for our project and following the README, I always seem to get a deprecation warning that AR doesn't know the attribute.

Using Rails 5.1.4 and activerecord-typestore 1.1.2:

class AddPreferences < ActiveRecord::Migration[5.1]
  def change
    add_column :users, :preferences, :jsonb
  end
end

class User < ApplicationRecord
  typed_store :preferences, coder: JSON do |s|
    s.boolean :email, default: true
  end
end

irb(main):001:0> User.first.email = false

W, [2017-11-30T08:50:57.209379 #26] WARN -- : DEPRECATION WARNING: email is not an attribute known to Active Record. This behavior is deprecated and will be removed in the next version of Rails. If you'd like email to be managed by Active Record, add attribute :email to your class. (called from irb_binding at (irb):1)

If I turn off typedstore accessors and add attribute :email to the class, then the warning goes away.

Is this a known issue/expected or am I doing something wrong?

Thanks!

byroot commented 6 years ago

It's not a known issue, so thanks for reporting it.

byroot commented 6 years ago

I've opened a PR to update the tested version of AR, and indeed the warning is there: https://github.com/byroot/activerecord-typedstore/pull/60

I'll try to fix this.

rafaelfranca commented 6 years ago

Thank you for the report. Fixed on master