我在同一个表中有一个包含父类别Id的类别表。并添加关联以加入分类子类别的同一个表。下面是我的表结构,表关联代码和删除功能。但删除不工作:(。
表格结构: -
1234567890abcdef
模特协会: -
CREATE TABLE IF NOT EXISTS `category` (
`Cat_Id` int(11) NOT NULL,
`Cat_Code` varchar(255) NOT NULL,
`Cat_Desc` text NOT NULL,
`CreatedBy` varchar(255) NOT NULL,
`ParentId` int(11) NOT NULL DEFAULT '0',
`GstPercentage` double NOT NULL DEFAULT '0',
`CreatedDate` datetime NOT NULL,
`UpdateDate` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `category`
--
ALTER TABLE `category`
ADD PRIMARY KEY (`Cat_Id`),
ADD UNIQUE KEY `Cat_id` (`Cat_Id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `category`
--
ALTER TABLE `category`
MODIFY `Cat_Id` int(11) NOT NULL AUTO_INCREMENT;
删除功能: -
public function initialize(array $config)
{
parent::initialize($config);
$this->table('category');
$this->displayField('Cat_Id');
$this->primaryKey('Cat_Id');
// association for the same table join
$this->belongsToMany('Parents', [
'className' => 'Category',
'joinTable' => 'category',
'foreignKey' => 'Cat_Id',
'targetForeignKey' => 'ParentId',
]);
// used to associate the table with user table (join)
$this->belongsTo('Users', [
'className' => 'Users',
'foreignKey' => 'CreatedBy',
'propertyName' => 'user'
]);
}