Sha256: 470fe7335cf21aba197bbb4871ab1f4dd3bf2335d9e9e09a1f9e471b39757912

Contents?: true

Size: 2 KB

Versions: 24

Compression:

Stored size: 2 KB

Contents

# Upgrading from 0.X.X to 1.0.0

## Jsonb Accessor declaration

In 0.X.X you would write:

```ruby
class Product < ActiveRecord::Base
  jsonb_accessor :data,
    :count, # doesn't specify a type
    title: :string,
    external_id: :integer,
    reviewed_at: :date_time, # snake cased
    previous_rankings: :integer_array, # `:type_array` key
    external_rankings: :array # plain array
end
```

In 1.0.0 you would write:

```ruby
class Product < ActiveRecord::Base
  jsonb_accessor :data,
    count: :value, # all fields must specify a type
    title: :string,
    external_id: :integer,
    reviewed_at: :datetime, # `:date_time` is now `:datetime`
    previous_rankings: [:integer, array: true], # now just the type followed by `array: true`
    external_rankings: [:value, array: true] # now the value type is specified as well as `array: true`
end
```

There are several important differences. All fields must now specify a type, `:date_time` is now `:datetime`, and arrays are specified using a type and `array: true` instead of `type_array`.

Also, in order to use the `value` type you need to register it:

```ruby
# in an initializer
ActiveRecord::Type.register(:value, ActiveRecord::Type::Value)
```

### Deeply nested objects

In 0.X.X you could write:

```ruby
class Product < ActiveRecord::Base
  jsonb_accessor :data,
    ranking_info: {
      original_rank: :integer,
      current_rank: :integer,
      metadata: {
        ranked_on: :date
      }
    }
end
```

Which would allow you to use getter and setter methods at any point in the structure.

```ruby
Product.new(ranking_info: { original_rank: 3, current_rank: 5, metadata: { ranked_on: Date.today } })
product.ranking_info.original_rank # 3
product.ranking_info.metadata.ranked_on # Date.today
```

1.0.0 does not support this syntax. If you need these sort of methods, you can create your own type `class` and register it with `ActiveRecord::Type`. [Here's an example](http://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute).

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
jsonb_accessor-1.4-java UPGRADE_GUIDE.md
jsonb_accessor-1.4 UPGRADE_GUIDE.md
jsonb_accessor-1.3.10 UPGRADE_GUIDE.md
jsonb_accessor-1.3.10-java UPGRADE_GUIDE.md
jsonb_accessor-1.3.8 UPGRADE_GUIDE.md
jsonb_accessor-1.3.7-java UPGRADE_GUIDE.md
jsonb_accessor-1.3.7 UPGRADE_GUIDE.md
jsonb_accessor-1.3.6 UPGRADE_GUIDE.md
jsonb_accessor-1.3.5 UPGRADE_GUIDE.md
jsonb_accessor-1.3.4 UPGRADE_GUIDE.md
jsonb_accessor-1.3.3 UPGRADE_GUIDE.md
jsonb_accessor-1.3.2 UPGRADE_GUIDE.md
jsonb_accessor-1.3.1 UPGRADE_GUIDE.md
jsonb_accessor-1.3.0 UPGRADE_GUIDE.md
jsonb_accessor-1.2.0 UPGRADE_GUIDE.md
jsonb_accessor-1.1.0 UPGRADE_GUIDE.md
jsonb_accessor-1.0.0 UPGRADE_GUIDE.md
jsonb_accessor-1.0.0.beta.7 UPGRADE_GUIDE.md
jsonb_accessor-1.0.0.beta.6 UPGRADE_GUIDE.md
jsonb_accessor-1.0.0.beta.5 UPGRADE_GUIDE.md