Closed rlzdesenv closed 1 year ago
I have the same difficulty
Hi @rlzdesenv, Please log the executed queries with the Laravel query log or a tool like debugbar.
this is the related select
select
distinct "documentos".*,
"safira"."areas"."ficha_tecnica_id" as "laravel_through_key"
from
"geral"."documentos"
inner join "safira"."area_documento" on "safira"."area_documento"."documento_id" = "geral"."documentos"."id"
inner join "safira"."areas" on "safira"."areas"."id" = "safira"."area_documento"."area_id"
where
"area_documento"."tipo" = 'alvara'
and "safira"."areas"."ficha_tecnica_id" in (2)
and "geral"."documentos"."deleted_at" is null
and "safira"."area_documento"."deleted_at" is null
and "safira"."areas"."deleted_at" is null
return $fichaTecnica->load([
'areas:*',
'areas.uso:id,nome',
'areas.tipo:id,nome',
'areas.estrutura:id,nome,sisobra',
'areas.destinacao:id,nome,sisobra',
'areas.operacao:id,nome,sisobra',
'areas.tipoRegularizacao:id,nome',
'responsaveis:*',
'responsaveis.formacao:id,nome,tipo,conselho_id',
'responsaveis.formacao.conselho:id,nome,sigla',
'responsaveis.contribuinte:id,nome,documento',
'proprietarios:id,nome,documento',
'alvaras:documentos.*'
]);
the load was a little out of the standard to declare in the load 'alvaras:documentos.*'
, plus it brings the data of the documento, however I cannot relate in the loading of the documento the user of the table documento 'alvaras:documentos.user:id,name'
the normal declaration should be 'alvara.documentos:*'
'alvara.documentos.usuario:id,nome'
, but it doesn't work
I need to bring only the data from the "documents", but it is bringing all the data from the relationships involved that way it brings me all data from all related tables
What do you mean by "all the data from the relationships"? What query is executed in this case?
'alvara.documentos.usuario:id,nome', but it doesn't work
Is there an error or is the query result just wrong?
if I declare 'alvaras.documentos.usuario:id,nome' like this I get this error
Illuminate\Database\Eloquent\RelationNotFoundException Call to undefined relationship [documentos] on model [App\Models\Documento].
I apologize, I think I was wrongly relating the load.
I was using 'alvara.documentos.usuario:id,nome'
but I preferred to use only 'alvaras.usuario:id'
because the relationship below is directly linked to the module I want
<?php
class FichaTecnica extends Model
{
protected $table = 'safira.ficha_tecnicas';
public function alvaras(): HasManyThrough
{
return $this->hasManyDeep(Documento::class, [Area::class, AreaDocumento::class]);
}
}
I was using 'alvara.documentos.usuario:id,nome' but I preferred to use only 'alvaras.usuario:id'
So alvara.documentos.usuario:id,nome
works but alvaras.usuario:id
doesn't work, right? What error are you getting in this case?
I need to bring only the data from the "documents", but it is bringing all the data from the relationships involved, I also need to bring the "document" using group by id of the "document"
that way it brings me all data from all related tables
this way only from the documents table, however it gets weird I can't load the related models for example I needed to bring the user who created the document