gpt4 book ai didi

php - Yii 关系 : get data form another table

转载 作者:行者123 更新时间:2023-11-29 08:56:12 24 4
gpt4 key购买 nike

我有电影表和 TblMovieVideos 表,并且我与这些表有关系,所以我需要从 TblMovieVideos 中获取“youtube_id”,其中“trailer=1”

我想我需要通过这段代码获得结果,但这是错误的错误:$model->tblMovieVideos[$model->id]->trailer = 1 ->youtube_id ??????

(已附加数据库图像)

电影模特:

public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'tblCinemaMovies' => array(self::HAS_MANY, 'TblCinemaMovies', 'movie_id'),
'tblDays' => array(self::HAS_MANY, 'TblDay', 'movie_id'),
'tblGenres' => array(self::HAS_MANY, 'TblGenre', 'movie_id'),
'tblMoviePhotos' => array(self::HAS_MANY, 'TblMoviePhoto', 'movie_id'),
'tblMovieVideos' => array(self::HAS_MANY, 'TblMovieVideo', 'movie_id'),
'tblShowtimes' => array(self::HAS_MANY, 'TblShowtime', 'movie_id'),
);
}

TblMoviesVideos 模型:

public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'movie' => array(self::BELONGS_TO, 'TblMovie', 'movie_id'),
'tblSpotlights' => array(self::HAS_MANY, 'TblSpotlight', 'video_id'),
);
}

enter image description here

enter image description here

索引: enter image description here

最佳答案

您可以通过以下方式获取所有有预告片的电影:

$movies=Movie::model()->with(array('tblMovieVideos'=>array('condition'=>'trailer = 1')))->findAll();

但由于您想要的是 youtube_id,请尝试以下操作:

$id = 1;//Id of the movie for which you are trying to find the video
$videos = TblMoviesVideos::model()->findAllByPk($id, 'trailer = 1');
foreach ($videos as $video)
{
echo $video->youtube_id;
}

干杯。

关于php - Yii 关系 : get data form another table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9917657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com