Code Monkey home page Code Monkey logo

Comments (25)

alexzarbn avatar alexzarbn commented on May 20, 2024 4

@ldiebold,

Found the cause - it is RelationsResolver@guardRelations that wipes out eager loaded nested relations, because there is no "business.manager" relation on the model itself.

Will include the fix in v1.2 👌

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024 2

Hi @ldiebold,

First of all, thank you for the kind words!

Honestly, I thought this is already supported 🤔
Let me check, and I will get back to you after running a few tests.

But either way, this is definitely something that will be introduced, if it is not supported.

from laravel-orion.

PascalHesselink avatar PascalHesselink commented on May 20, 2024 1

@PascalHesselink,
Have you tried explicitly setting the resource class?
If resources are located in non-conventional folder, indeed, it may not find them.

I'm using the default namespace/conventional way of creating resources. I've noticed if you want to manually 'register' them, they have to been put in a controller. In my case the 'user' relationship doesn't have a controller because it is a nested relationship.

In that case you need to do the following:

  • Have a resource for ForumCategory
  • In ForumCategory resource you need to define the threads relation like Laravel documentation suggests (meaning you also need to have a resource for Thread)
  • In Thread resource you need to define the user relation, again the same way.
  • In User resource you can then exclude the email property

Got it! I made a fault in my resource nesting, you're awesome!

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024 1

This is fixed in 1.1.3 release.

In 1.2 release I am planning to add the ability to specify wildcard nested relations. It will remove the need for listing all nested relations, if all of them should be available for inclusion:

protected function includes(): array
{
    return ['user', 'posts.*']; // this is NOT released yet
}

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024 1

Relations whitelisting using wildcards is added in 1.2 release.

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024 1

Hi @alireza2281,

Whitelisting of relations using wildcards is only supported in the includes method.
Please upgrade to v1.2.1 - it contains the fix to make ['user.profile', 'user.assignedCategory'] whitelisting work.

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024 1

@alireza2281,

Recursive stuff is so confusing sometimes 😅

Please update to v1.2.2 - it will solve the problem.

from laravel-orion.

PascalHesselink avatar PascalHesselink commented on May 20, 2024

@ldiebold,

Found the cause - it is RelationsResolver@guardRelations that wipes out eager loaded nested relations, because there is no "business.manager" relation on the model itself.

Will include the fix in v1.2 👌

I'm also facing this problem, would love to see this fix! Amazing work @alexzarbn.

from laravel-orion.

ldiebold avatar ldiebold commented on May 20, 2024

@alexzarbn thankyou!!!

Also want to point out how beautiful your code is. Simple comments, easy to navigate... A true joy 💓

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024

@PascalHesselink

Thank you ~

Got it, will plan to implement the fix for this weekend.

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024

@ldiebold

It took a lot of refactoring to get to its current state 😄
Thank you, will keep it that way ~

from laravel-orion.

PascalHesselink avatar PascalHesselink commented on May 20, 2024

@PascalHesselink

Thank you ~

Got it, will plan to implement the fix for this weekend.

I noticed it works when you list them up, in my case:

        return [
                'forumCategories',
                'forumCategories.threads',
                'forumCategories.threads.user',
        ];

But it doesn't recognise the resources, so I wanted to exclude the email from the 'user' relationship, but that didn't work through the resources. I hope you can also look to that!

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024

@PascalHesselink,

Have you tried explicitly setting the resource class?
If resources are located in non-conventional folder, indeed, it may not find them.

from laravel-orion.

PascalHesselink avatar PascalHesselink commented on May 20, 2024

@PascalHesselink,

Have you tried explicitly setting the resource class?
If resources are located in non-conventional folder, indeed, it may not find them.

I'm using the default namespace/conventional way of creating resources. I've noticed if you want to manually 'register' them, they have to been put in a controller. In my case the 'user' relationship doesn't have a controller because it is a nested relationship.

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024

@PascalHesselink,
Have you tried explicitly setting the resource class?
If resources are located in non-conventional folder, indeed, it may not find them.

I'm using the default namespace/conventional way of creating resources. I've noticed if you want to manually 'register' them, they have to been put in a controller. In my case the 'user' relationship doesn't have a controller because it is a nested relationship.

In that case you need to do the following:

  • Have a resource for ForumCategory
  • In ForumCategory resource you need to define the threads relation like Laravel documentation suggests (meaning you also need to have a resource for Thread)
  • In Thread resource you need to define the user relation, again the same way.
  • In User resource you can then exclude the email property

from laravel-orion.

joshuahill1609 avatar joshuahill1609 commented on May 20, 2024

I was listing out my relations four levels deep like @PascalHesselink mentioned in their comment. The new 1.1.3 breaks this for some reason, I have not been able to dive into why but wanted to leave an update in case anyone else is having the same issue. I went back to 1.1.1 and my relations load again.
This may be the intended functionality and I just need to change how I eager load relations.

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024

Hi @joshuahill1609,

Thank you for bringing that up. Could you please share the whitelisted includes array from your controller and the request url (with ?include= query parameter)?

from laravel-orion.

joshuahill1609 avatar joshuahill1609 commented on May 20, 2024

I am using the alwaysIncludes() function in the controller to always load these nested resources.

/**
    * The relations that are loaded by default together with a resource.
    *
    * @return array
    */
    protected function alwaysIncludes() : array
    {
        return [
            'divisions', 
            'divisions.cost_codes', 
            'divisions.cost_codes.tasks', 
            'divisions.cost_codes.production_codes', 
            'divisions.cost_codes.tasks.area',
            'divisions.cost_codes.tasks.nodes',
            'divisions.cost_codes.tasks.nodes.production_codes',
            'divisions.cost_codes.tasks.manifest',
            'divisions.cost_codes.tasks.manifest.materials',
        ];
    }

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024

@joshuahill1609,

Does the Devision model follow the same naming convention for defining relation methods (e.g. cost_codes) as it is listed in alwaysIncludes method or it is defined as costCodes?

from laravel-orion.

joshuahill1609 avatar joshuahill1609 commented on May 20, 2024

@alexzarbn Yes, the relation method is cost_codes().

This is working for me now and broke when I upgraded to the new version.

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024

@joshuahill1609,

Okay, I will dig more into this issue.

from laravel-orion.

alireza2281 avatar alireza2281 commented on May 20, 2024

Hello, i have updated to version 1.2 but when i use user.* in always include i get this error:
Call to undefined relationship [*] on model [Modules\\User\\Entities\\User].
and when i put these relations ['user.profile', 'user.assignedCategory'] it just fetch the last relation

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024

@joshuahill1609,

Could you please upgrade to v1.2.2 and see, if it works? I was not able to replicate the issue though..

from laravel-orion.

alireza2281 avatar alireza2281 commented on May 20, 2024

@alexzarbn hi again,
there is one more thing that if i try to access relation from one level below the example i mentioned earlier would cause the same problem.
i mean if i always include related.relatedProduct.primaryImage and then related.relatedProduct.variation
it would return just variation

from laravel-orion.

alexzarbn avatar alexzarbn commented on May 20, 2024

Hi @alireza2281,

Thank you, I will look into the issue.

from laravel-orion.

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.