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