belongsTo('book', 'book_id', 'id'); } protected static function init() { self::afterInsert(function ($row) { $pk = $row->getPk(); $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]); }); } public function getSexList() { return ['1' => '男频','2' => '女频']; } public function getSexTextAttr($value, $data) { $value = $value ? $value : $data['sex']; $list = $this->getSexList(); return isset($list[$value]) ? $list[$value] : ''; } }