Comments (4)
I'm closing this, please let me know if you need any help here, and I'll reopen it 🙂
from store_model.
Hi @joshRpowell! Thanks for the report, I'll do my best to take a look at the issue later this week
from store_model.
@joshRpowell I was able to reproduce it! The problem is that in schema you set up "{}"
as a default, and then change default to {}
in the attribute declaration. When replacing :jsonb
with store models you removed attribute-level override, so the app crashes, when at least one jsonb field gets default string value. There are two options you have:
- bring back defaults in attributes definition
- change schema to use
{}
instead of"{}"
Here is a full example (save it to file, run createdb railstestdb
and then execute the file with Ruby):
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"
gem "rails"
gem "pg"
gem "factory_bot_rails"
gem "store_model"
end
require "active_record"
require "action_controller/railtie"
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "railstestdb")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
enable_extension "plpgsql"
create_table "worker_options", id: :serial, force: :cascade do |t|
t.jsonb "options", default: "{}", null: false
t.jsonb "data", default: "{}", null: false
# Option 1:
# t.jsonb "options", default: {}, null: false
# t.jsonb "data", default: {}, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
class WoCases
include StoreModel::Model
attribute :uri, :string
end
class Options
include StoreModel::Model
attribute :id, :integer
attribute :number, :string
attribute :receipt_number, :string
end
class WorkerOption < ActiveRecord::Base
attribute :data, WoCases.to_type
attribute :options, Options.to_type
# Option 2:
# attribute :data, WoCases.to_type, default: {}
# attribute :options, Options.to_type, default: {}
end
FactoryBot.define do
factory :worker_option, class: 'WorkerOption' do
data { { "uri" => 'http://localhost:3000/api/v1/work_flows/1/case_machines/1/cases' } }
trait :valid_options do
options { { "id" => 666, "number" => "NUMBER", "receipt_number" => "RECEIPT_NUMBER" } }
end
end
end
puts FactoryBot.create(:worker_option).inspect
# The following line always works, because all the attributes are set up!
puts FactoryBot.create(:worker_option, :valid_options).inspect
from store_model.
@DmitryTsepelev Thanks for the prompt response. I made the recommended adjustments and it resolved my issues.
from store_model.
Related Issues (20)
- One of depending on another model's column HOT 4
- Validate any Hash HOT 1
- Encrypt attributes HOT 2
- Aliasing an attribute HOT 1
- GraphQL input type fails to cast HOT 4
- ArgumentError: wrong number of arguments (given 1, expected 0) in random model HOT 3
- Assignment Doesn't work in OneOf case HOT 3
- Delegation of `fetch` to `attributes` causes issues HOT 2
- NameError: uninitialized constant StoreModel::Types::ArrayType HOT 3
- Default values for attributes when retrieving the store model HOT 1
- Decoding Custom Types HOT 1
- Allow an option to disallow "UnknownAttributes" behavior HOT 1
- ActiveRecord validation contexts don't propagate HOT 1
- Override methods HOT 3
- Broken defaults in 2.0 HOT 2
- Attribute encryption with ActiveRecord::Encryption HOT 1
- StoreModel Stringifying json when saving. HOT 14
- accepts_nested_attributes_for allow partial updates HOT 2
- [QUESTION] How preserve data on update? HOT 1
- JSON deserializing empty string, leads to nil error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from store_model.