1
I have a model that takes the data with a with in the Standard, to take correlated data, there is form of these correlated data come only some specific fields and not all the data of the table?
I tried to do this:
return ModelPai::with(array('nomeFuncaoNaModel1'=>function($query){
$query->select('Campo1_da_tabela1');
}))->with('nomeFuncaoNaModel2')->findOrFail($id);
The function on the model looks like this.
public function nomeFuncaoNaModel1()
{
return $this->hasMany('App\Model1','id_model1','id');
}
As it is, if you comment on the $query line, it returns the data I want, but with all fields and only desire field 1 of the relation, I have not been able to accomplish this part, and it has generated me great doubt.
According to the documentation in Doc, Only a select should be required after $this->hasMany()->select(['fields]); however, it does not work
You could use Join, but Join does not separate the fields, it puts the fields all together in the same object,
data.campo1Tabela1
data.campo2Tabela1
data.campo3Tabela1
data.campo1Tabela2
If only he put it separately (if he knows any way it would be useful to know.) so that it would look like this.
data.campo1Tabela1
data.campo2Tabela1
data.campo3Tabela1
data.Tabela2.campo1Tabela2
Place the line where: "take the data with a with in the Standard, to get correlated data"
– Miguel
I added the example and how I did it.
– Andersoney Rodrigues
See if this works: https://pastebin.com/sMfEDudd
– Miguel
No, the whole object comes empty.
– Andersoney Rodrigues