I think (I don’t really know, if I’m wrong please correct me), this is actually Many To Many relationship between Medias table and other tables (Users, Messages, Posts).
So, I am creating the middle table named Media_links to connect the Many To Many relation between these tables.
I am thinking to define the hasMany() relation for the Medias tables, but didn’t want to define its belongsTo() relationship.
I didn’t try anything yet. Posting this thread just to get insights first.
3
Answers
Nothing really happens to your application, other than if you were to access you’r pivot table, you won’t be able to call any relationships from it.
If you are creating pivot table you should create a belongsToMany relation , this provides you sync(), attach() methods . Otherwise you can simply create hasMany relation. What you are trying to do actually ?
hasMany
andbelongsTo
is aone-to-many
, NOTmany-to-many
.about your question, you can access the relation whereever you define it, but not the inverse unless you define it!
i.e.
if you have a Teacher and Student model
Teacher Model
Student Model