-
Notifications
You must be signed in to change notification settings - Fork 2
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
Unable to update values #7
Comments
Hey @sqlninja I was not testing it against rails 6. If you’ll find anything meanwhile pls create a pr. I’ll check it at the evening MSK |
@sqlninja Also pls make sure to use it like class MyPreciousModel < ActiveRecord::Base
include Leafy::Mixin::Schema[:active_record]
self.leafy_data_attribute = :my_json_or_jsonb_attribute
end so basically that's all If you will still have issues with it please post the error backtrace in the comment below. |
@sqlninja also you can take a look at this test |
So I had my model already declared the way you stated: class TeamContact < ApplicationRecord
include Leafy::Mixin::Schema[:active_record]
...
end although I didn't have the class TeamContact < ApplicationRecord
include Leafy::Mixin::Schema[:active_record]
self.leafy_data_attribute = :leafy_data
...
end I still get: NoMethodError: undefined method `leafy_values=' for #<TeamContact:0x00007fa5b01e2960> This is my simple test that I am running via rails console: tc = TeamContact.last
tc.update(
leafy_fields_attributes: [
{ name: "hs_city", type: :string}
]
)
tc.leafy_values = { "hs_city": 'Gallatin'} the entire error is: NoMethodError: undefined method `leafy_values=' for #<TeamContact:0x00007fa5b01e2960>
Did you mean? leafy_fields=
from /Users/johnhenderson/.rvm/gems/ruby-2.6.5@stacked-sports/gems/activemodel-6.0.3.1/lib/active_model/attribute_methods.rb:432:in `method_missing' |
@sqlninja hey there. Looks like you are using the same model for both hosting fields definition and storing values. |
Ok I am concerned this just doesn't work in ActiveRecord... If following the readme, it seems to indicate that you can call: target.leafy_values = { "id_1": 123, "id_2": "test", "id_3": Time.new(2018,10,10, 10,10,10, "+03:00"), "junk": "some junk data" } yet that file above seems to show that calling field_value_collection = ::Leafy::FieldValueCollection.new(leafy_fields, ar_json: activerecord_json_column?) but in that file it raises an error: def leafy_fields
raise(RuntimeError, "Leafy: leafy_fields method is not defined")
end so regardless of trying to use this in one model, this just doesn't seem to work. Again, am I just missing something obvious? Thanks |
pinging... |
Using Rails 6, ActiveRecord, and Postgres
After retrieving an existing model from the database, I updated the model to have a "custom" field:
Although, upon trying to pull the values (which I'd expect to be nil) I get an
undefined method 'leafy_values'
error. So no getter...So I thought perhaps I had to assign values (even though that shouldn't be the case)
But this threw basically the same error
undefined method 'leafy_values='
so no setter...But indeed the object did store the "custom" field:
Am I missing something from the Read me? Or perhaps another initializer/config?
The text was updated successfully, but these errors were encountered: