我有所有的模型。我需要在教義中定義關係,並使用教義建立一個查詢。我如何建立這條查詢Zend
查詢沒有教條,它工作正常。
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");
只是爲了告訴你,資產模型具有一對多的關係與AssetSiteLink
任何想法?
我相信,如果你在你不需要使用基類corectly塞汀了關係在查詢中加入語句。它會自動選取相關記錄 – Developer 2011-05-26 08:18:26