Where to put the Model code in php

Asked

Viewed 52 times

2

I have some tables in my db between them are

post_has_categoria
post
categoria

in My Models I have Category.php and Contest.php where should be the sql responsible for the post_has_category?

  • For me each table should be represented by a model. But I believe this also has something to do with your logic. Maybe it has to do with personal opinion...

  • Are you using some ORM to perform queries or are doing it all by hand?

1 answer

3


Assuming that this sql/method would check "is there a category in the post?" this same sql/method would be in the Post class following the IE (information Expert) standard - whoever has/knows the information should perform the task. In this case, only the Post class knows if it has a category.

  • Gee, I’m interested. It’s good to leave a source about these things, Information Expert is part of the same MVC standard, or something apart?

  • @Daniel in my research I found this Default to assign responsibilities: Expert

  • @Daniel information expert is a software standard that is part of the GRASP design principles that says that the class that does a certain action is the one that has the knowledge to do it! https://en.wikipedia.org/wiki/GRASP_(Object-oriented_design)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.