我有數據庫這樣
accounts
Laravel三通許多一對多雄辯關係
- ID
- 名
contacts
- ID
- ACCOUNT_ID
account_communications
- ID
- ACCOUNT_ID
和接觸模型:
class Contact extends Model
{
public function Account()
{
return $this->belongsTo('App\Account');
}
public function AccountCommunication()
{
return $this->hasManyThrough('App\AccountCommunication','App\Account');
}
}
Account模型
class Account extends Model
{
public function AccountCommunication()
{
return $this->hasMany('App\AccountCommunication');
}
public function Contact()
{
return $this->hasMany('App\Contact');
}
}
AccountCommunication模型
class AccountCommunication extends Model
{
public function Account()
{
return $this->belongsToMany('App\Account');
}
}
在我的控制器
class ContactController extends Controller
{
public function index()
{
$contacts = Contact::with('Account')->with('AccountCommunication')->paginate(10);
dd($contacts);
}
}
告訴我這個錯誤
SQLSTATE [42S22]:列未找到:1054未知列在 '字段列表'(SQL 'accounts.contact_id':選擇
account_communications
*,accounts
。contact_id
fromaccount_communications
inner joinaccounts
onaccounts
。id
=account_communications
。account_id
其中accounts
。contact_id
(20))
關係映射他們似乎錯了。是'account_communications'中間表嗎? –
是...... – paranoid