How to Recognize the Antipattern
The following clues may mean that you have Magic Beans:
-
“How can I pass a custom SQL query to a model?”
The question suggests that you’re using a database access class as a model class. You shouldn’t have to pass SQL queries to the model—the model class should encapsulate any queries it needs.
-
“Should I copy complex model queries to all my controllers, or should I code them once in an abstract controller?”
Neither of these solutions gives you the stability or simplicity you are looking for. You should code complex queries within the model, exposed as part of the interface of the model. That way, you follow the Don’t Repeat Yourself (DRY) principle, and you make the model’s usage simpler.[40]
-
“I have ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access