blueprinter icon indicating copy to clipboard operation
blueprinter copied to clipboard

Not able to use transformer when it is in included view

Open bhooshiek-narendiran opened this issue 5 years ago • 11 comments

view :skeleton do
    include_view :summary
    excludes :actors, :ticket_id
  end

  view :summary do
    field :actors_response_info, name: :actors
    transform FieldTransformer
  end

Here when I directly use the view: summary then the FieldTransformer is working. But I can't able to use the same transformer when it is included in another view. Like if view: skeleton is called, the FieldTransformer is not working. This is because we are not taking the included views transformer while rendering the output. Can I raise a pr for this one?

bhooshiek-narendiran avatar Jul 13 '20 10:07 bhooshiek-narendiran

@bhooshiek-narendiran Good find, thank you - definitely feel free to open a PR to solve this.

adamwells avatar Aug 18 '20 18:08 adamwells

Thanks, @adamwells Will do.

bhooshiek-narendiran avatar Aug 19 '20 05:08 bhooshiek-narendiran

Could really use this. Would be great if someone could do a code review and accept this PR. @bhooshiek-narendiran, thanks for fixing this btw.

aarona avatar Oct 16 '20 07:10 aarona

Thanks for the PR @bhooshiek-narendiran!

Separate but related issue: views should inherit transformers from the base class but they do not. This is demonstrated by a new PR https://github.com/procore/blueprinter/pull/247. It is unfortunately not fixed by your change.

I wonder if we could make a generic fix for both issues... I don't currently have time to dig deeper but wanted to at least share these preliminary findings here (a workaround for me is to simply re-include the transformer in every single view, so that's what I'm doing until I have time to help with this proper fix).

cooperka avatar Nov 19 '20 00:11 cooperka

HI @cooperka! Can you elaborate me the above issue with an example? So I'll try to fix that one in this PR.

bhooshiek-narendiran avatar Nov 19 '20 10:11 bhooshiek-narendiran

Yes please see the linked PR #247 with a working unit test (it's failing, in order to demonstrate the issue) 🙂 Let me know if you have questions related to it, thanks for your help!

cooperka avatar Nov 19 '20 22:11 cooperka

Hi, @cooperka One doubt whether the view transformer should override the class transformers(parent and child) or both should execute (view transformers + class transformers)?

bhooshiek-narendiran avatar Nov 20 '20 15:11 bhooshiek-narendiran

Hmm, if both execute, is there a way to STOP the parent from executing through some syntax? If there's no way to stop it, I think it must override entirely. But I will leave that up to the library author during PR review.

cooperka avatar Nov 20 '20 15:11 cooperka

currently, we have options to differentiate default ones(parent & child class transformers) and view transformers. So I thought, We can use view transformers if it is configured or else (parent or child class transformers) will execute. If we need to block parent class transformers alone then we need some parameter to differentiate that one.

bhooshiek-narendiran avatar Nov 20 '20 16:11 bhooshiek-narendiran

Following this thread. Just wanted to chime in real quick. This might be over engineering but maybe a solution similar to how rack middleware Is implemented?

aarona avatar Nov 20 '20 16:11 aarona

My advice is "keep it simple", whatever it does can be documented in the readme. If using BOTH transformers and adding new syntax for blocking the parent is easier, that's fine with me, but my assumption is that overriding would be easier (because that seems to be how it currently works, no change needed).

The only current issue for me is when a transformer is NOT defined in a view, it SHOULD inherit the base transformer, and currently it does not.

cooperka avatar Nov 20 '20 17:11 cooperka

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Nov 10 '23 01:11 github-actions[bot]