从连接表中推出数据不可用

时间:2021-01-06 17:02:20

I'm trying to show the first image of an imagealbum in a list. But when creating a query i cannot access the $album->getImageuri() method in the foreach loop.

我正试图在列表中显示imagealbum的第一张图像。但是在创建查询时,我无法访问foreach循环中的$ album-> getImageuri()方法。

$albums = \ApAlbumQuery::create()
            ->join('ApAlbum.ApAlbumImage', \Propel\Runtime\ActiveQuery\Criteria::LEFT_JOIN)
            ->join('ApAlbumImage.ApImage', \Propel\Runtime\ActiveQuery\Criteria::LEFT_JOIN)
            ->where('ApAlbum.visibility is not null')
            ->groupBy('ApAlbum.Id')
            ->orderByStartdate("ASC")
            ->find();

foreach($albums as $album)
{
    echo $album->getImageuri(); // not working?
}

When running the sql-query created with the Propel ->toString() method everything is present.

运行使用Propel - > toString()方法创建的sql-query时,一切都存在。

Anybody know what i'm doing wrong?

谁知道我做错了什么?

1 个解决方案

#1


Try adding the ImageURI column using ->withColumn():

尝试使用 - > withColumn()添加ImageURI列:

$albums = \ApAlbumQuery::create()
        ->join('ApAlbum.ApAlbumImage', \Propel\Runtime\ActiveQuery\Criteria::LEFT_JOIN)
        ->join('ApAlbumImage.ApImage', \Propel\Runtime\ActiveQuery\Criteria::LEFT_JOIN)
        ->withColumn('ApAlbumImage.ApImage.ImageURI')
        ->where('ApAlbum.visibility is not null')
        ->groupBy('ApAlbum.Id')
        ->orderByStartdate("ASC")
        ->find();

foreach($albums as $album)
{
    echo $album->getImageuri(); // not working?
}

From your ->join() syntax, I assume that your're using different schemata

从你的 - > join()语法,我假设你使用不同的模式

#1


Try adding the ImageURI column using ->withColumn():

尝试使用 - > withColumn()添加ImageURI列:

$albums = \ApAlbumQuery::create()
        ->join('ApAlbum.ApAlbumImage', \Propel\Runtime\ActiveQuery\Criteria::LEFT_JOIN)
        ->join('ApAlbumImage.ApImage', \Propel\Runtime\ActiveQuery\Criteria::LEFT_JOIN)
        ->withColumn('ApAlbumImage.ApImage.ImageURI')
        ->where('ApAlbum.visibility is not null')
        ->groupBy('ApAlbum.Id')
        ->orderByStartdate("ASC")
        ->find();

foreach($albums as $album)
{
    echo $album->getImageuri(); // not working?
}

From your ->join() syntax, I assume that your're using different schemata

从你的 - > join()语法,我假设你使用不同的模式