jeudi 28 janvier 2016

Different db connection for models using hasManyThrough relationship in laravel 5.1

I am trying to use the hasManyThrough relationship in laravel 5.1 but the sql query is not using the appropriate prefix defined in each connection for each model used. I have 3 models 2 of which use the same connection and one of them uses a different one. The only difference between the connections is the prefix the database is the same.

  • Model A has connection A which uses prefix A_
  • Model B has connection B which uses prefix B_
  • Model C has connection B which uses prefix B_

The relationship:

Inside Model B:

public function relationshipWithA()
{
    return $this->hasManyThrough(A::class, C::class, 'Cid', 'Aid');
}

The final query logic is correct but instead of using the B_ prefix for the joined tables its using the A_ prefix for all the tables in the query.

Is this a bug/limitation of laravel? Is there a solution to this or I will have to do manual join to achieve what I want?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1nAqWqB
via IFTTT

Aucun commentaire:

Enregistrer un commentaire