How to get multiple data when you hit a GetAll Request using Fractal on Laravel 5.3

I have a table metrics that stores all the metrics data, and I also have a table metrics_history that stores the history data of all the metrics.

I have setup the relations with the metrics and metrics_history table in the following way:

Inside metric model:

[QUOTE] public function history()
{
return $this->hasMany(MetricHistory::class, ‘metric_id’, ‘metric_id’);
}[/QUOTE]

inside metrics_history model:

[QUOTE] public function metric()
{
return $this->belongsTo(Metric::class, ‘metric_id’, ‘metric_id’);
}
[/QUOTE]

Now, when I hit: metrics/1?include=history

I get a response with a history node with all histories related to this particular metric. This works Perfectly fine!

But, when I hit metrics?include=history

I do get a response of all the metrics with the history node but the history node is empty.

Why is that so? What am I missing?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.