【发布时间】:2025-12-19 05:15:06
【问题描述】:
我有所有的模型。我需要在教义中定义关系并使用教义构建查询。
没有教义的查询可以正常工作。
SELECT * FROM asset_site_link l
join assets a on l.assetID = a.id
join assetTypes t on t.id = a.assetTypeID
join assetCategories c on c.id = a.categoryID
where t.name="image" AND c.name = "static_banner"
and l.siteID = "2"
我的第一次尝试是这样的,但没有奏效。
$q = Doctrine_Query::create()
->select('r.*')
->from('assetManagement_Model_asset r')
->leftJoin('r.assetTypeID t')
->leftJoin('r.categoryID c')
->leftJoin('r.assetSiteLink l')
->where('r.isDeleted = 0')
->andWhere('t.name = ?', "image")
->andWhere('c.name = ?', "static_banner")
->andWhere ('l.siteID = ?', "2");
虽然下面的查询工作正常(没有assetSiteLink 连接)
$q = Doctrine_Query::create()
->select('r.*')
->from('assetManagement_Model_asset r')
->leftJoin('r.assetTypeID t')
->leftJoin('r.categoryID c')
->where('r.isDeleted = 0')
->andWhere('t.name = ?', "image")
->andWhere('c.name = ?', "static_banner");
只是告诉你 Asset 模型与 AssetSiteLink 是一对多的关系
有什么想法吗?
【问题讨论】: