H
H
HaruAtari2014-03-01 13:03:17
Yii
HaruAtari, 2014-03-01 13:03:17

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

2 answer(s)
D
devunion, 2014-03-01
@HaruAtari

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.

E
Egor Mokeev, 2014-03-01
@zetamen

Normally, for such classes you can inherit from CModel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question