Have you viewed any of the laracast on this?
http://laravel.io/forum/search?query=many+to+many
I think your problem is the ContactContact model. I'm not sure why you need it, because it looks like you're using the pivot table as a model as well as the pivot table for the two other connected models. The sql error tells you exactly what's happening. It's trying to join on a non-unique table alias. I would have to see more code to help you.
rickshawhobo said:
I think your problem is the ContactContact model. I'm not sure why you need it, because it looks like you're using the pivot table as a model as well as the pivot table for the two other connected models. The sql error tells you exactly what's happening. It's trying to join on a non-unique table alias. I would have to see more code to help you.
I am using ContactContact
to link Contact records with other Contacts
as well as relationship/role details, etc.
Even if I removed the use of the Model ContactContact
and only use contact_contact as a pivot table, I suspect I would still encounter the same non-unique table alias
error.
I don't have a problem self joining. Here is my User model with both relationships using the same pivot
public function childs()
{
return $this->belongsToMany('User', 'user_user', 'parent_id', 'child_id');
}
public function parents()
{
return $this->belongsToMany('User', 'user_user', 'child_id', 'parent_id');
}
If you need data in your pivot you should look into "withPivot".
Thank you @rickshawhobo, withPivot
put me on the right track.
It's late now, but once I clean things up, I will share what I did.
Laracasts: Favorites Part 1 & Part 2 were very informative as well.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community