【发布时间】:2017-09-17 13:57:06
【问题描述】:
我正在尝试在表之间创建一个简单的关系:
- attribute_type -
id
name
- category -
id
name
description
所以我创建了一个数据透视表来链接它们:
- attribute_type_category -
attribute_type_id
category_id
有模型关系:
关于 AttributeType.php
public function category() {
return $this->belongsToMany('App\AttributeTypeCategory', 'attribute_type_category', 'attribute_type_id', 'category_id');
}
关于 AttributeTypeCategory.php
public function category() {
return $this->belongsToMany('App\Category');
}
一切似乎都很好,但我收到以下错误:
SQLSTATE[42000]:语法错误或访问冲突:1066 不唯一 表/别名:'attribute_type_category'(SQL:选择
attribute_type_category.*,attribute_type_category.attribute_type_id为pivot_attribute_type_id,attribute_type_category.category_id如pivot_category_idfromattribute_type_category内连接attribute_type_categoryattribute_type_category.id=attribute_type_category.category_id在哪里attribute_type_category.attribute_type_id= 1)
你有什么想法吗? 谢谢!
【问题讨论】:
标签: php sql laravel eloquent relationship