Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a Has-Many Relationship ONLY

I have a: has_and_belongs_to_many :friends, :join_table => "friends_peoples".

To add a friend I do: @people.followers << @friend which create the relationship and a new person profile.

Now I'd like to delete the relationship ONLY and not the person profile.

I tried @people.friends.delete(guilty.id) but it deletes the person profile and not the relationship.

Any idea?

like image 988
Alextoul Avatar asked Oct 03 '10 23:10

Alextoul


People also ask

What is Cascade on Delete laravel?

Laravel Soft Cascade is a package that makes it easy to perform soft cascade deletes and restores on related models using soft deleting.

How do I delete a pivot table in laravel?

Show activity on this post. If that way doesn't solve your problem, you can delete Pivot table records to using the DB option like below ; DB::table('any_pivot_table')->where('x_column', $xParameter)->delete(); You can solve the problem just like this.


1 Answers

Have you tried this?

@people.friends.delete(guilty)
like image 187
Michiel de Mare Avatar answered Oct 19 '22 03:10

Michiel de Mare