0

Currently, I'm working on laravel 6 with MySQL database.

So I want to fetch records with has Many relations wise.

Fetch Training Intensity Records vie multiple ids -- see image

TrainingGoalModel.php

/**
 * training_intensity_details => get multiple intensity with current goal
 *
 * @return void
 */
public function training_intensity_details()
{
    return $this->hasMany(TrainingIntensity::class, 'id', 'training_intensity_ids');
}

GoalController

$query = $query->with('training_intensity_details')->get();

,both applied,

$query = $query->with(['training_intensity_details'])->get();

But, Relation not applying. Please, Help me.

2
  • 1
    Relationship cannot work on comma separated ids. if you have hasMany relation with TrainingIntensity's table, then you should add goal id in training_intensities table instead of storing in goals table. Commented Dec 12, 2019 at 5:21
  • Can we manage customised relationship for this problem Commented Sep 16, 2020 at 16:44

1 Answer 1

1

Try..

   public function training_intensity_details()
    {
        return $this->hasMany(TrainingIntensity::class, 'training_intensity_ids', 'id');
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Please add some explanation to your answer such that others can learn from it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.