Code Monkey home page Code Monkey logo

Comments (6)

staudenmeir avatar staudenmeir commented on June 29, 2024

Is this a suggestion for this repository or the Laravel documentation?

from eloquent-has-many-deep.

NicksonYap avatar NicksonYap commented on June 29, 2024

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.

staudenmeir avatar staudenmeir commented on June 29, 2024

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.

NicksonYap avatar NicksonYap commented on June 29, 2024

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.

NicksonYap avatar NicksonYap commented on June 29, 2024

Using MySQL view as pivot table will also solve the Union problem mentioned in: #8

from eloquent-has-many-deep.

staudenmeir avatar staudenmeir commented on June 29, 2024

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)

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.