Declaring hasMany() implies belongsTo() declaration on the other side?

In a model A I declared a hasMany() relationship with a model B.

Does this imply that I must declare a belongsTo() relationship in B ?

In short, no. It’s not mandatory but makes logical sense.

1 Like

Hey @begueradj! :wave:

No need to define the relation on both models if you will use it only one-way.

There’s a note on this in the documentation.

1 Like

There is no need to define a relationship on both the models. Setting it one-way on a single model is all that’s required.

Docs need improvement. This implies that a one way relationship is all that’s needed to set up both ways, which is not unreasonable to believe.

Well, I agree somehow, but you can suggest your pull request to improve the documentation :slight_smile: @kswope

While I’m learning the framework and working on a project I’m making a list of notes from the point of view of a beginner. Maybe I’ll go nuts with that later.

But because of the looming adonis5 I don’t know what improvements, suggestions, etc are still useful!

1 Like