Code Monkey home page Code Monkey logo

Comments (8)

flugg avatar flugg commented on May 19, 2024

The 'items.results' = null is actually a bug and something I'm addressing for the next release. You should, however, see results nested under items as well. Could you paste the results method in your ItemTransformer?

from laravel-responder.

andcl avatar andcl commented on May 19, 2024

Of course,

public function results(Item $item)
{
    return $this -> collection($item -> results, new ResultTransformer);
}

Nothing special with this method, I guess...
What is remarkable is that the key 'items.results' = null only appears one time, at the end of the last item...
Thanks.

from laravel-responder.

flugg avatar flugg commented on May 19, 2024

Hmm, I'm working on a rewrite of the package improving the including of relations, which should solve these issues. I'll try to recreate the issue described above, but could you try to change the results method to the following:

public function results(Item $item) {
    return responder()->transform($item->results, new ResultTransformer)->getResource();
}

from laravel-responder.

andcl avatar andcl commented on May 19, 2024

Of course.
I have modified the method with your suggestion and I get the same 'items.results' = null key at the end...
(Assuming that in the controller I have:
...new SurveyTransformer) ->include(['items.results']) -> respond();
)
I really appreciate your help.

from laravel-responder.

flugg avatar flugg commented on May 19, 2024

Hey, sorry for taking so long. After some investigating, I've located the bug. The issue is when using the wildcard relations on deeply nested transformers, like:

protected $relations = ['*'];

For some reason, that doesn't work as intended for nested relations. However, it can be fixed by explicitly specifying the relationship, which in your case would be to add $relations = ['results'] to ItemTransformer.

I tested the same with the upcoming version 2 of the package, and everything worked as expected. So this should be solved by that in a couple weeks time - in the mean time, you will have to be explicit with the relations (which often can be a good idea anyway, as it can restrict access to some relations for security reasons).

Let me know if that solved all your issues!

from laravel-responder.

andcl avatar andcl commented on May 19, 2024

Thank you very much for your help, but that change does not fix the issue in my specific case...
I have done the changes to ItemTransformer so that protected $relations = ['results'], and it keeps returning the 'items.results' = null at the end.
I have also tried with both

return responder()->transform($item->results, new ResultTransformer)->getResource();
and
return $this -> collection($item -> results, new ResultTransformer);
in the results method, no luck...

However, noticed that when I change protected $relations = ['items'] in SurveyTransformer, results does not appear, but neither 'items.results' = null key.

Thanks again.

from laravel-responder.

flugg avatar flugg commented on May 19, 2024

Oh, I thought the issue was that you didn't get the 'results' data at all. Is this still the case? The 'items.results': null at the end is a bug I tried to fix earlier this winter. However, while trying to fix it, I realised the entire code for handling relations was way too complex, and instead of fixing it, I ended up rewriting big parts of the package (for the better). These changes will be rolled out soon and will fix the 'items.results': null bug. In the meantime, the bug shouldn't actually break anything, only add an unnecessary JSON field to the response.

from laravel-responder.

flugg avatar flugg commented on May 19, 2024

With the release of version 2 of the package, this bug should have vanished.

from laravel-responder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.