I’m trying to understand when is the appropriate time to use Doctine_Table classes and which methods to store there vs. in the regular model class file.
Also, is it good practice to use the findBy* methods?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use methods in the model class that operate on an instance of that model – a user record that you’ve retrieved, a blog post etc. For example, you may have a
setPassword()method on a user record, which sets the password for that user using your own algorithm, or agetTitleUppercased()method on a blog post which returns the blog title but uppercased.Methods on the table class are used for operating on the table as a whole – generally, you’ll find query methods here that aren’t available via the Doctrine magic methods. Queries that involve specific joins, specific parameters (eg
WHERE date > NOW() AND foo.bar < 5) should go in here.It’s good practice to use the
findBy*methods if your query is simple – don’t reinvent the wheel. Note that these are quite specific, so it’s great for things likefindOneByEmail('test@example.com'), but if you need to be more specific, move your query into the table class into its own method.