因此,我正在努力學習Kohana,當涉及到他們的ORM模塊時,我遇到了相當多的障礙。 當試圖設置一對多ORM對象時,我能夠更新/插入來自父模型的信息,但它不會允許我關聯(插入/更新)任何新的子項。
爲了清楚起見,這裏是我的數據庫結構...
recipes
--id
--recipe
--directions
--servings
ingredients
--id
--recipe_id
--amount
--serving
items
--id
--item
......我的模特...
class Model_Recipe extends ORM
{
protected $_has_many = array('ingredient' => array());
}
class Model_Ingredient extends ORM
{
protected $_belongs_to = array('recipe' => array());
protected $_has_one = array('item' => array());
}
class Model_Item extends ORM
{
protected $_belongs_to = array('ingredient' => array());
}
......和我的控制器.. 。
class Controller_Recipe extends Controller
{
function action_save_form()
{
$recipe = ORM::factory('recipe', 1);
$recipe->ingredient->recipe_id = 1;
$recipe->ingredient->amount = 1;
$recipe->ingredient->measurement_type = 'tablespoon';
$recipe->ingredient->save();
$recipe->ingredient->item->item = 'butter';
$recipe->ingredient->item->ingredient_id = $recipe->ingredient->id;
$recipe->ingredient->item->save();
}
}
我毫不猶豫地承認這是由於我的無能,但我已經通過源代碼瞭解了docs/wiki/read(ing),並且一直無法找到任何接近的東西。感謝任何人可能有的幫助/想法
編輯:重新閱讀後,它可能不是很清楚。我正在嘗試做的是更新$ recipe對象,然後更新/添加配料,以及它們的一對一子對象(項目),如下所示:
如果有幫助,我使用Kohana 3.1.2 – JoeCortopassi 2011-05-13 05:10:27