Support the ongoing development of Laravel.io →
Laravel Eloquent
Last updated 2 years ago.
0

Hi @carbonnanotubes,

You have specified the incorrect arguments to the hasOneThrough() function.

As per the docs "The third argument is the name of the foreign key on the intermediate model. The fourth argument is the name of the foreign key on the final model. The fifth argument is the local key, while the sixth argument is the local key of the intermediate model".

0

Thanks @faisal for your reply

maybe hasManyThrough is not the way I should be getting the part that is related to the job. I'm not able to follow the conventions due to the tables I need to work with that I cannot change. SF_JOB does not have any reference to the ActiveJob Model.

Even if I try to eager load the part from the job model it returns null

App\Models\ActiveJob::query()->with('model', 'model.part')->first();

=> App\Models\ActiveJob {#5627
     session_id: "941",
     job: "1824660505",
     machine: "",
     last_updated: "",
     production_quantity: "",
     scrap_quantity: ""
     machine_status: "",
     model: App\Models\Job {#5637
       JOB: "1824660505",
       LOT: "1824660505",
       SEQ: "1",
       WC: "",
       ORD_QTY: "1100",
       ITEM: "",
       PCS_HOUR: "",
       MFG_CLOSE_DATE: null,
       START_DATE: "2022-10-05 07:30:00.000",
       DUE_DATE: "2022-10-06 00:00:00.000",
       REL_DATE: "2022-10-04 14:11:16.000",
       COMPLETE_QTY: ".0000",
       WO_NUM: "",
       WO_LINE: "",
       POST_DATE: "2022-10-04 14:12:01.843",
       CREW_SIZE: "1",
       SHIFT: " ",
       END_DATE: "2022-10-05 19:36:00.000",
       CUSTOMER: "",
       COMMENTS: null,
       part: null,
     },
   }
App\Models\ActiveJob::query()->with('model', 'model.part')->first()->model->part;

// returns null

App\Models\ActiveJob::query()->with('model')->first()->model->part;

//returns the correct model
Last updated 2 years ago.
0

If you know how to rewrite the hasOneThrough relationship using this extra context of a graphical representation of the db relationships. I'm open to this as well

https://i.imgur.com/84ZXL48.png

0

I figured out the hasOneThrough Relationship

public function part()
{
    return $this->hasOneThrough(Item::class, Job::class, 'JOB', 'ITEM', 'job', 'ITEM');
}
Last updated 2 years ago.
0
Solution selected by @carbonnanotubes

Hello friends, I just want to write an essay but I don't know how to do it so I'm searching online for a cheap website that will help me write my essay on a very low budget because I don't have a lot of money to spend on it. After finding a website like https://www.topwritersreview.com/reviews/educibly/ where I can see many websites that help you write an essay and they are all inexpensive, I decided to use educibly to

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.