0
我無法保存一些HABTM數據。CakePHP保存與同一型號的HABTM關係
我的模型「類別」與本身HABTM關係稱爲「子類別」
$this->Category->create();
$c["Category"]["display_order"] = $this->Category->getNextDisplayOrder();
$c["Category"]["title"] = $this->request->data["title"];
$c["SubCategory"]["category_id"] = $id; //The id of the parent category
$new_cat = $this->Category->saveAll($c);
這將創建我的新的類別,並將其保存在數據庫中的精品,但是ID是被保存在錯誤的順序子類別表。 (category_id =>我剛剛創建的新貓ID,subcategory_id => parent_id)
任何想法爲什麼ID保存在錯誤的列?
這是我HABTM關係
public $hasAndBelongsToMany = array(
'SubCategory' => array(
'className' => 'Category',
'joinTable' => 'categories_subcategories',
'foreignKey' => 'category_id',
'associationForeignKey' => 'subcategory_id',
'unique' => 'keepExisting',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
我想創建一個類,並在同一時間,存放一段關係p是它的父母($ id) – user195257 2013-05-08 16:27:19