Closed maxacarvalho closed 1 month ago
Hi @maxacarvalho,
When I call the client relationship I get a null response back
What does your code look like?
Hi @staudenmeir
Thanks for your speedy reply. But I just realised that I can get it to work with the Laravel standard hasOneThrough
and hasManyThrough
relationships 🤦🏽
Here's the solution:
AwsSmsUsageReport
model:
public function client(): HasOneThrough
{
return $this->hasOneThrough(
Client::class,
Notification::class,
'id',
'id',
'notification_id',
'client_id'
);
}
Client
model:
public function awsSmsUsageReports()
{
return $this->hasManyThrough(
AwsSmsUsageReport::class,
Notification::class,
);
}
Hi, thanks for your nice package. I think I'm doing something wrong, I can't make it work with my use case.
What I have is:
nick_comunica_aws_sms_usage_reports
nick_comunica_notifications
clients
So, an entry in the
nick_comunica_aws_sms_usage_reports
table belongs to an entry in thenick_comunica_notifications
table which belongs to an entry in theclients
table.In my
AwsSmsUsageReport
model I added the traitZnck\Eloquent\Traits\BelongsToThrough
and the following method:Then I instantiate a record from the
AwsSmsUsageReport
model:$report = AwsSmsUsageReport::query()->find(15);
When I call the
client
relationship I get anull
response back.By inspecting the SQL query that's running I can see that the query misses the
notification_id
in the call to theclients
table:Any help?
Thank you!