如何在CakePhp中仅获取带有图像的产品

如何在CakePhp中仅获取带有图像的产品,cakephp,find,model-associations,Cakephp,Find,Model Associations,你需要额外使用contain,至少对我来说是这样 (由于递归=-1): 连接只是安装配置。如果不指定数据,您将只获得一个模型的数据 您是否使用可包含的行为?这是最简单的解决办法。 如果不是,请尝试将recursive设置为0或1 PS:您的第二个别名在“条件”中是错误的(应该是PhotoSmall)。首先,您将recursive设置为-1,无论您进行何种查找,它都会为您提供产品数据 为什么不在产品模型的查找中执行AND条件,如下所示: 'contain' => array('PhotoSm

你需要额外使用contain,至少对我来说是这样 (由于递归=-1):

连接只是安装配置。如果不指定数据,您将只获得一个模型的数据

您是否使用可包含的行为?这是最简单的解决办法。 如果不是,请尝试将recursive设置为0或1


PS:您的第二个别名在“条件”中是错误的(应该是PhotoSmall)。

首先,您将recursive设置为-1,无论您进行何种查找,它都会为您提供产品数据

为什么不在产品模型的查找中执行AND条件,如下所示:

'contain' => array('PhotoSmall', 'PhotoBig'),
注意:递归必须至少是一个,因为您需要相关数据

$this->Product->recursive = -1;
$conditions = array('Product.category_id'=> $cats);
$joins = array(
    array('table' => 'photos',
        'alias' => 'PhotoBig',
        'type' => 'INNER',
        'conditions' => array(
            'Product.id = PhotoBig.product_id',
        )
    ),
    array('table' => 'photos',
        'alias' => 'PhotoSmall',
        'type' => 'INNER',
        'conditions' => array(
            'Product.id = PhotoBig.product_id',
        )
    )
);
$this->paginate = array(
    'limit' => 12,
    'conditions' => $conditions,
    'joins' => $joins,
);
'contain' => array('PhotoSmall', 'PhotoBig'),
    $this->Product->find('all', array('recursive' => 1, 'conditions' => array(
    "NOT" => array('PhotoSmall.id' => NULL, 'PhotoBig.id' => NULL))));