Skip to content
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

Upgrade to V7 documentation seems to be inaccurate and it doesn't work as expected #507

Open
lostie opened this issue Jul 20, 2021 · 1 comment

Comments

@lostie
Copy link
Contributor

lostie commented Jul 20, 2021

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
@lostie
Copy link
Contributor Author

lostie commented Jul 21, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant