skip to Main Content

I am missing a laravel relation or I just don’t get it…
it is not hasOneThrough or belongsToThrough

The relation is as in the topic:

an Invoice (fkey customer_id) belongsTo Customer
that Customer hasOne BankData (fkey customer_id)

Am I missing an "eloquent way" for that relation? I could not find any answer to this …
I’d like to query all Invoices with that customers bankdata with a relation

edit:
actually I was thinking way to complex … I was working with Invoices and needed the customers bankData, without loading the whole customer, which I did not need. since both models do have the customer_id, a simple join did the trick

2

Answers


  1. Chosen as BEST ANSWER

    actually I was thinking way to complex ... I was working with Invoices and needed the customers bankData, without loading the whole customer, which I did not need. since both models do have the customer_id, a simple join did the trick


  2. So
    $user->invoices is a hasMany relation
    $user->bankData is a hasOne relation

    Both can and should be called separately because you don’t want to get the relation for every invoice being loaded, it’s not going trough the invoice model due there’s no related field in your table for the bankData model and thus cannot be taken from that relation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search