2

I have a Product model and an Image model with a one to many relationship and I'm currently working with the Image model directly in the Product controller, should I be calling the "Image Controller" (that I currently don't have) to handle all of the image stuff? Keeping in mind that the image cant exist without a product.

0

1 Answer 1

10

There is no direct relation between a controller and a model, and you should never create controllers to 'match' your models.

A controller is used to represent routes/pathways through your application.

A model is used to hold persistent data within your database.

Sometimes, when creating a CRUD application, there is a common amount of controllers and models (i.e. Posts, Comments, Users etc). But that is not because of a 'rule' - just the nature of the CRUD application.

A controller could call a couple of different models, and that would be acceptable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.