Answer the question
In order to leave comments, you need to log in
How is it normal to create separate models for collections in Yii?
There is a Keyword model inherited from CActiveRecord. Contains a bunch of methods for working with a specific keyword. But there are also many methods for working with collections of keywords. Any searches, etc.
I’m thinking, maybe in order to simplify the class, it’s worth moving the methods of working with the collection into a separate class, say, KeywordCollection. And the methods will return lists of Keyword classes. This will allow you to describe in the Keyword class only the logic of working with a specific keyword. And unnecessary methods will be separate.
Tell me, is it normal to use this approach to organizing models?
Answer the question
In order to leave comments, you need to log in
In theory, the model should have the logic of working with the model itself. A collection of keywords is formally another model or part of another model. So it's definitely worth it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question