Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Have you viewed any of the laracast on this?
http://laravel.io/forum/search?query=many+to+many

Last updated 8 years ago.
0

@jimgwhit Yes, in fact I have many-to-many tagging working.

0

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.

0

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.

Last updated 8 years ago.
0

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".

0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.