我在更新与 graphQL 查询重命名的关系时遇到问题。以下是相关的架构和Laravel模型:拉拉维尔模型<?phpnamespace App\Models;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Relations\BelongsTo;use Illuminate\Database\Eloquent\Relations\BelongsToMany;class Lead extends Model{ /** * The attributes that are mass assignable. * * @var array */ // protected $fillable = [ // 'lead_type_id', // ]; protected $guarded = []; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ // ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ // 'created_at' => 'timestamp', // 'updated_at' => 'timestamp' ]; /** * Get the LeadActions for the Lead. */ public function leadActions() { return $this->hasMany(\App\Models\LeadAction::class); } /** * Get the clients for the Lead. */ public function clients(): BelongsToMany { return $this->belongsToMany(Client::class); } /** * Get the LeadType for the Lead. */ public function leadType(): BelongsTo { return $this->belongsTo(\App\Models\LeadType::class, 'lead_type_id'); }}?><?phpnamespace App\Models;use App\Models;use Illuminate\Database\Eloquent\Model;use Illuminate\Database\Eloquent\Relations\HasMany;class LeadType extends Model{ /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name' ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ // ];我遵循了Laravel命名约定,并将列命名为lead_type_id在潜在客户表上。如果我删除将lead_type关系重命名为 leadType,我可以成功运行更新突变,但我无法弄清楚如何让它使用列的正确名称(lead_type_id),同时保持关系重命名。任何帮助都非常感谢。
1 回答
万千封印
TA贡献1891条经验 获得超3个赞
你试过指令吗?我的意思是,你必须在你的中使用它,因为灯塔寻找名为的关系,并且由于没有定义,它假设这是一个参数。@renamelead_typeUpdateLeadInputlead_typelead_type
在模型中重命名关系,例如:
class Lead extends Model
{
public function lead_actions()
{
return $this->hasMany(\App\Models\LeadAction::class);
}
public function lead_type(): BelongsTo
{
return $this->belongsTo(\App\Models\LeadType::class, 'lead_type_id');
}
}
或
使用指令(我没有尝试过,但我的意思是它的工作原理是这样的):@rename
input UpdateLeadInput {
id: ID!
clients: UpdateClientsRelation
lead_type: UpdateLeadTypeRelation @rename(attribute: "leadType")
}
- 1 回答
- 0 关注
- 95 浏览
添加回答
举报
0/150
提交
取消