這是我在這裏的第一個問題,所以請儘量保持耐心與我:)symfony的推進:與標準錯誤填充物addJoin
我在一個怪異的行爲填充物體絆倒。
我開始將我項目中使用的objectQuery::create()-> ... ->find()
方法轉換爲$c = new Criteria(), $c-> ... objectPeer::doSelect($c)
,因爲我被告知不能在條件滿足時使用查詢。
我有一個函數,它返回商店物品的所有價格。或者至少做到了。我想不通的事情是這樣的:
舊代碼:
static public function shopGetPrices($id){
$prices = itemPriceQuery::create()->
addJoin(itemPricePeer::ITEM_ID, itemPeer::ID, Criteria::LEFT_JOIN)->
addJoin(itemPeer::CATEGORY_ID, categoryPeer::ID, Criteria::LEFT_JOIN)->
addJoin(categoryPeer::SHOP_ID, shopPeer::ID, Criteria::LEFT_JOIN)->
add(shopPeer::ID, $id)->find();
return $prices;
}
返回正確填充PropelObjectCollection
對象,通過它我可以用foreach去,和獲取/設置ITEMPRICE對象和屬性,我需要。
現在,新的代碼:
static public function shopGetPrices($id){
$c = new Criteria();
$c->addJoin(itemPricePeer::ITEM_ID, itemPeer::ID, Criteria::LEFT_JOIN)->
addJoin(itemPeer::CATEGORY_ID, categoryPeer::ID, Criteria::LEFT_JOIN)->
addJoin(categoryPeer::SHOP_ID, shopPeer::ID, Criteria::LEFT_JOIN)->
add(shopPeer::ID, $id);
return self::DoSelect($c);
}
返回itemPrice
對象的數組,但ITEMPRICE對象通過加入它們與相關的項目值填充。這意味着:當我打電話print_r(self::DoSelect($c));
它打印
Array
(
[0] => ItemPrice Object
(
[startCopy:protected] =>
[id:protected] => 47 <- id of joined item
[item_id:protected] => 9 <-foreign key to category object of joined item
[price:protected] => 0
[unit:protected] => Axe <- name of item, not unit (unit is like 'golden', 'iron', 'wood' or whatever)
[active:protected] =>
[collItemsOrder:protected] =>
[collItemsOrderPartial:protected] =>
[alreadyInSave:protected] =>
[alreadyInValidation:protected] =>
[polozkyObjednavkasScheduledForDeletion:protected] =>
[prisadyPolozkyObjednavkasScheduledForDeletion:protected] =>
[validationFailures:protected] => Array()
[_new:protected] =>
[_deleted:protected] =>
[modifiedColumns:protected] => Array()
[virtualColumns:protected] => Array()
)
[1] => ItemPrice Object
(
...等等。
標準和查詢對象之間可能存在一些關鍵的區別,我錯過了。我在谷歌,StackOverflow上搜索,誰知道在哪裏,但我沒有找到任何類似的解決方案。
這guy/gal有一個模糊的類似問題,但我沒有用我的標準addSelectColumn
,所以這對我來說是另一個死衚衕。
任何人都可以請指出我在正確的方向嗎?
什麼?在Propel 1.6中構建查詢的新方法比使用條件要容易得多。特別是當你寫*簡單*查詢。 Propel btw的哪個版本? – j0k
我使用symfony 1.4,並推動更新到1.6。我不知道有什麼更簡單的方法,喬布書談到這一點,而且我還在學習,所以我用我發現的。你能發佈我應該使用的任何引用嗎? – Kuro
關於Propel,你應該看看[documentation](http://www.propelorm.org/reference/model-criteria.html)。但是,你需要轉換這個查詢?因爲你讀到'ModelQuery'不好,標準更好? – j0k