Hi, it seems that when I use the type "relationship" in edit_fields in model config file, it strangely update the id fields instead of the key group I've set in $this->belongsTo('\App\Models\MtrGroup', 'group', 'group');. What confused me is that it just outputs the right result in columns, but doesn't work with edit_fields and filters. Table schema, eloquent model and model config is as follows, hope you can help me solve it, thx.
Table schema:
mtr_groups
CREATE TABLE `mtr_groups` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order` int(11) NOT NULL DEFAULT '0',
`group` varchar(20) NOT NULL DEFAULT '',
`name` varchar(50) NOT NULL DEFAULT '',
`active` enum('Y','N') NOT NULL DEFAULT 'N',
`created_time` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `order` (`order`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
mtr_mid_category
CREATE TABLE `mtr_mid_categories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order` int(11) NOT NULL DEFAULT '0',
`group` varchar(20) NOT NULL DEFAULT '',
`name` varchar(50) NOT NULL DEFAULT '',
`created_time` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `order` (`order`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;
Eloquent model:
MtrGroup.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MtrGroup extends Model
{
protected $table = 'mtr_groups';
public $timestamps = false;
protected $hidden = ['created_time'];
}
MtrMidCategory.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MtrMidCategory extends Model
{
protected $table = 'mtr_mid_categories';
public $timestamps = false;
protected $hidden = ['order', 'created_time'];
public function mtr_group()
{
return $this->belongsTo('\App\Models\MtrGroup', 'group', 'group');
}
}
Many mtr_mid_category belong to one group, and related by the key group (not id, it turns to be correct when I use id as foreign key), so why did edit and filter just update and select id? Is there any wrong here?
Hi, it seems that when I use the type "relationship" in edit_fields in model config file, it strangely update the
id
fields instead of the key group I've set in$this->belongsTo('\App\Models\MtrGroup', 'group', 'group');
. What confused me is that it just outputs the right result incolumns
, but doesn't work withedit_fields
andfilters
. Table schema, eloquent model and model config is as follows, hope you can help me solve it, thx.Table schema:
Eloquent model:
Model config file:
Many mtr_mid_category belong to one group, and related by the key group (not
id
, it turns to be correct when I useid
as foreign key), so why didedit
andfilter
just update and selectid
? Is there any wrong here?