【发布时间】:2017-11-11 01:35:20
【问题描述】:
我有以下三个模型:
class Category extends Eloquent
{
protected $primaryKey = 'categoryID';
public $timestamps = false;
protected $fillable = [
'categoryName',
];
public function categoriesfields()
{
return $this->hasMany(\App\Models\Categoriesfield::class, 'categoryID');
}
}
类别字段:
class Categoriesfield extends Eloquent
{
protected $primaryKey = 'fieldID';
public $timestamps = false;
protected $casts = [
'categoryID' => 'int'
];
protected $fillable = [
'fieldName_ar',
'categoryID'
];
public function category()
{
return $this->belongsTo(\App\Models\Category::class, 'categoryID');
}
public function categoriesoptions()
{
return $this->hasMany(\App\Models\Categoriesoption::class, 'fieldID');
}
}
类别选项:
class Categoriesoption extends Eloquent
{
protected $primaryKey = 'optionID';
public $timestamps = false;
protected $casts = [
'optionParent' => 'int',
'fieldID' => 'int'
];
protected $fillable = [
'fieldID'
];
public function categoriesfield()
{
return $this->belongsTo(\App\Models\Categoriesfield::class, 'fieldID');
}
}
当我运行这个查询时,我得到了这个错误:
$data= Category::with('category.categoriesfields')-
>with('category.categoriesfields.categoriesoptions')
->where('fieldID', '=', 3)->get();
SQLSTATE[42S22]:找不到列:1054 'where 子句'中的未知列 'fieldID'(SQL:select * from categories where fieldID = 3)
任何帮助请知道是什么问题!!?
【问题讨论】:
-
$data= Category::with('category.categoriesfields')->with('category.categoriesfield.categoriesoptions') ->where('fieldID', '=', 3)->得到();试试这个
-
同样的错误。