Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Advanced Polymorphic: Many-to-Many

Premium
2:40

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

RJ
Ravindrasinh Jadav ✓ Link copied!

Shouldn't the pivot table have model_id and model_type instead of just photo_id ?

PK
Povilas Korop ✓ Link copied!

It's not photo_id, it's photoable_id

A
amauro ✓ Link copied!

shouldn't there be a unique constraint or index for all three fields (photo_id, photoable_it and photoable_type) to avoid multiple assignements of one photo to a user?

PK
Povilas Korop ✓ Link copied!

Good idea, that would be a good extra constraint.