Giter Club home page Giter Club logo

Comments (7)

staudenmeir avatar staudenmeir commented on May 19, 2024 1

This is an issue of the underlying HasManyThrough relationship and will be fixed in Laravel 5.8: laravel/framework#25812

Until then, you can use this workaround (only for lazy loading):

$address->address_with_billing_account()->getQuery()->get(['billing_accounts.*'])

from eloquent-has-many-deep.

NicksonYap avatar NicksonYap commented on May 19, 2024

Were my function parameters for hasManyDeep incorrect? It seems to work though

from eloquent-has-many-deep.

staudenmeir avatar staudenmeir commented on May 19, 2024

Please post the migrations of all three tables.

from eloquent-has-many-deep.

NicksonYap avatar NicksonYap commented on May 19, 2024

Address:

image


Account:
image


BillingAccount:

image

from eloquent-has-many-deep.

NicksonYap avatar NicksonYap commented on May 19, 2024

@staudenmeir

I manage to get around this problem earlier but this time it's causing other problems

Though this is a hasOneDeep(), I'd need it to return an array that why hasManyDeep() was used instead

from eloquent-has-many-deep.

NicksonYap avatar NicksonYap commented on May 19, 2024

@staudenmeir

To clarify the issue:


Eager loaded from hasManyDeep():

image


However, eager loaded ID for the BillingAccount is wrong:

BillingAccount Id should be 1, not 2.
2 is the Account's Id.

image


I discovered a pattern:

Those that has uses only primary keys id on top will cause this exact eager loading issue

It's possible there are id conflicts

from eloquent-has-many-deep.

NicksonYap avatar NicksonYap commented on May 19, 2024

@staudenmeir

Oops, just saw ur reply after posting.

Where is the suggested code supposed to be placed?
In the controller?

--EDIT:

turned it into an attribute and it worked! my.. the hours i spent on this 😭

    public function getAddressWithBillingAccountAttribute(){
        return $this->address_with_billing_account()->getQuery()->get(['crm_billing_accounts.*']);
    }

Thanks a lot!

This is an issue of the underlying HasManyThrough relationship and will be fixed in Laravel 5.8: laravel/framework#25812

Until then, you can use this workaround (only for lazy loading):

$address->address_with_billing_account()->getQuery()->get(['billing_accounts.*'])

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.