Comments (25)
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.
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,
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 thethreads
relation like Laravel documentation suggests (meaning you also need to have a resource forThread
)- In
Thread
resource you need to define theuser
relation, again the same way.- In
User
resource you can then exclude the
Got it! I made a fault in my resource nesting, you're awesome!
from laravel-orion.
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.
Relations whitelisting using wildcards is added in 1.2 release.
from laravel-orion.
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.
Recursive stuff is so confusing sometimes 😅
Please update to v1.2.2 - it will solve the problem.
from laravel-orion.
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.
@alexzarbn thankyou!!!
Also want to point out how beautiful your code is. Simple comments, easy to navigate... A true joy 💓
from laravel-orion.
Thank you ~
Got it, will plan to implement the fix for this weekend.
from laravel-orion.
It took a lot of refactoring to get to its current state 😄
Thank you, will keep it that way ~
from laravel-orion.
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.
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.
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.
@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 thethreads
relation like Laravel documentation suggests (meaning you also need to have a resource forThread
) - In
Thread
resource you need to define theuser
relation, again the same way. - In
User
resource you can then exclude theemail
property
from laravel-orion.
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.
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.
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.
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.
@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.
Okay, I will dig more into this issue.
from laravel-orion.
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.
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.
@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.
Hi @alireza2281,
Thank you, I will look into the issue.
from laravel-orion.
Related Issues (20)
- Error on viewAny policy in relation controller routes
- Please add an ability to use Alova.js instead Axios for Orion.makeHttpClientUsing(...) HOT 1
- Modular (non-standard) app architectures
- Case-insensitive does not work with JSON field type HOT 1
- filterableBy nested relation: Call to undefined method HOT 1
- Using 'include' on PATCH/update requests give "1054 Unknown column 'include' in 'field list' " HOT 1
- How can i set default get record order by id descending order? HOT 1
- Call to a member function requestedRelations() on null HOT 1
- GET request pending after STORE operation on IOS ONLY HOT 1
- Sorting included relationships HOT 1
- Regression: impossible to call sub-relations with the QueryBuilder HOT 4
- Can't use 'max_nested_depth' => 1 with in Request HOT 4
- Unable to Publish Vendor Config in Laravel-Orion HOT 1
- Including more content in the OpenAPI 3 specs HOT 1
- Customize Database Driver HOT 1
- artisan orion:specs does not work HOT 2
- Search endpoint not present HOT 6
- Documentation error: Access level to [Controller]::filterableBy() must be public (as in class Orion\Http\Controllers\BaseController) HOT 1
- Custom Resource not working HOT 2
- Meilisearch Compatibility HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-orion.