gpt4 book ai didi

php - [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]在 Laravel 中使用 model::with 时转换失败

转载 作者:行者123 更新时间:2023-12-03 11:22:53 25 4
gpt4 key购买 nike

我正在使用 Laravel eloquent ORM,并且我定义了一些关系:

class Item extends Model
{
protected $table = 'IV00102';
protected $primaryKey = 'ITEMNMBR';
protected $trimmableAttributes = ['ITEMNMBR', 'PRIMVNDR'];

public function backorderQuantities(){
return $this->hasOne(BackorderQuantity::class, 'ITEMNMBR', 'ITEMNMBR')->where('SOPTYPE', 5);
}

}
和关系模型为:
class BackorderQuantity extends Model
{

protected $table = 'SOP10200';
protected $primaryKey = 'ITEMNMBR';
protected $trimmableAttributes = ['ITEMNMBR', 'SOPNUMBE', 'SOPTYPE', 'QUANTITY', 'QTYREMAI'];

public function item(){
return $this->belongsTo(Item::class, 'ITEMNMBR', 'ITEMNMBR');
}

}
当我尝试使用定义的关系获取数据时出现问题: Item::with('backorderQuantities')->where('PRIMVNDR', Auth::user()->vendor_id)这样做会导致此错误: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Conversion failed when converting the varchar value 'X123RECORD231' to data type int我可以在不预先加载执行 2 个查询然后循环并检查关系的情况下完成这项工作,如下所示:
foreach ($objects as $view) {
if($view->backorderQuantities){
// do things
}
}
但这给我带来了许多问题,更像是创可贴而不是合法的修复。我想知道是否有解决方案,或者 SQL 服务器和 MSSQL 服务器之间的兼容性是否会失效。

最佳答案

此错误已解决。我仍然相当确定这是一个兼容性问题,但这是代码以某种方式自行解决的奇怪实例之一。如果/当我将来隔离并再次遇到问题时,我将更新此答案。

关于php - [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]在 Laravel 中使用 model::with 时转换失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63043953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com