Comments (6)
Is this a suggestion for this repository or the Laravel documentation?
from eloquent-has-many-deep.
Suggestion/Note in this repo to point out that MySQL's view is a possible solution /workaround for highly advanced relationships (with conditions, or unions etc)
While being able to work with eager loading
and then of course when Laravel's Migrations officially support creating MySQL Views + documentation then a lot of us would avoid this headache...
Did you get my reasoning to use MySQL's View?
If it doesn't make sense then it's alright just posting to possible save someone else's time
from eloquent-has-many-deep.
I really like the view idea, but I don't think it belongs in this repository.
What would be an example for a relationship with conditions?
from eloquent-has-many-deep.
You're right, its not for this repo but it is an alternative solution
Note that the key problem to solve is advanced/conditional deep relationships.
MySQL queries has no issues with this but eloquent wasn't built for it. (which this repo is trying to solve)
Example:
BillingAccount has many Orders
Order has many Coupons
Coupons has one Invoice
Invoice has many Payment
As you can see, a BillingAccount has Ordered some Coupons which has an Invoice that can be pending Payment or already paid in full (multiple Payments to cover single Invoice)
With MySQL view,
You can create 1 fake relationship pivot table for each relation in Laravel such that, you can get:
BillingAccount->paidCoupons()
BillingAccount->unpaidCoupons()
In total, 2 fake pivot tables
from eloquent-has-many-deep.
Using MySQL view as pivot table will also solve the Union problem mentioned in: #8
from eloquent-has-many-deep.
I've created a package for merging relationships using views:
https://github.com/staudenmeir/laravel-merged-relations
from eloquent-has-many-deep.
Related Issues (20)
- Using with a Belongs To Many? HOT 1
- Data duplication on hasManyTrough with pivot HOT 3
- Relations not shown in artisan command model:show HOT 3
- Ambigious column reference 'id' HOT 1
- I can't get to conclude this relationship HOT 1
- HasOneTrhough MorphOne HOT 1
- issue with composite keys when doing a relation between 2 tables HOT 2
- Dynamic relationship property returning empty collection HOT 4
- collision with compoships HOT 1
- need help with hasManyDeep with belongsTo HOT 2
- distinct - paginate HOT 1
- Public Page -> belongsTo CompanyBranch -> morphMany Addresses HOT 1
- HasManyDeep Relation Issue HOT 2
- relations eager loading HOT 2
- I'm getting the results for all users - help please HOT 3
- Pivots not returned the same way HOT 3
- HasOneDeep is not generic HOT 5
- Laravel 11 HOT 4
- CompositeKey not included when installed. HOT 3
- Select without laravel_through_key doesnt return query result with PHP while query direct on db does HOT 8
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 eloquent-has-many-deep.