forest-rails
forest-rails copied to clipboard
Upgrade to V7 documentation seems to be inaccurate and it doesn't work as expected
Expected behavior
The following section:
The signature of hooks functions has changed. In order to support the hooks for global and bulk smart action, record is no longer sent to the hook. You must change the way you get the record information. After:
[...]
:hooks => {
:load => -> (context) {
id = ForestLiana::ResourcesGetter.get_ids_from_request(context[:params])[0];
# or
id = context[:params][:data][:attributes][:ids][0];
record = model.find(id) <<<<<<<<<<<<<<< This doesn't work
field = context[:fields].find{|field| field[:field] == 'a field'}
field[:value] = record.a_props;
return context[:fields];
}
}
[...]
Is expected to retrieve the record
Actual behavior
record_id = context[:params][:data][:attributes][:ids][0]
=> "f4540e93-38b8-47ca-8c22-035580125959"
model.find(record_id)
=> undefined method `find' for #<ForestLiana::Model::Collection:0x000000012c6e19c8 @name="Asset"
::Asset.where(id: record_id).count
=> 1
But the ForestLiana::Model::Collection instance doesn't seem to support find.
Context
- Package Version: 7.0.0
- Rails Version: 6.1.4
FYI, this is the approach I've used to solve it:
model_class = ForestLiana::SchemaUtils.find_model_from_collection_name(model.name)
model_class.find(id)