Lets say there are 2 tables:
videos (id, file_name)
matches (id, videos_id, match_number)
I want to get video file_name by match_number. I have read that using eloquent, you can avoid joins.
So I try various things from examples like this:
Video.php
class Video extends Eloquent {
protected $table = 'videos';
public function matches()
{
return $this->hasMany('Match', 'videos_id');
}
/*public function match()
{
return $this->belongsTo('Match', 'id');
}*/
/**
* @param $matchNumber
* @return mixed
*/
public function getByMatchNumber($matchNumber)
{
return $this
->matches()
//->select('videos.file_name')
//->limit(10)
->where('matches.match_number', $matchNumber)
->file_name;
// ->match()
}
}
But nothing works.
I think I am assuming well that video hasMany matches because in reality there are many matches which have same video.
So how it should look?
Update
Match_number column is unique, like id. There cannot be multiple matches with same match number. And there is only one video for one match. Limit(10) just was doing to try without where condition, to not get millions of results. But same video is assigned to many matches.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire