Let's say I have 3 classes A, B and C, A (PK_A, att1, att2) B (PK_B, att1, att2, att3) C (PK_C, att1, att2) and then the associative class is like this Associative (#PK_A, #PK_B, #PK_C, att1, att2)
the problem is that I don't know how to associate those 3 classes (A, B and C) all together
In the end I should have something like this A (1, 'value', 'value') , B (1, 'value', 'value', 'value') , C (1, 'value', 'value') and Associative (1, 1, 1, 'value', 'value')
The answer maybe simple but I never used n-ary relationships and I'm new to laravel (eloquent)
That's clear, but what is the use case. This is simply pivot table (and pivot object) and if you need to call it only together with one of A,B or C in the context of a relationship with one of the other 2, then it's trivial.
So desribe how you need to use that in order to get suggestions.
Let's imagine I want to create A, B and C objects and attach them all together, when using two classes (many to many) it's simple ( A->Bs()->attach(id) ) but how about the three all together at once ?
btw, thanks for answering my questions ;)
With 3 models it's just the same:
pivot table a_b_c: a_id,b_id,c_id
relations on A:
belongsToMany('B','a_b_c')->withPivot('c_id'); // if needed to know related C
belongsToMany('C','a_b_c')
and accordingly on B and C
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community