Hello guys,
I’m trying to figure out the best way of creating a model. I have those simple tables: article, tag, and articlesTags (many-many table).
In article model I have some methods like:
getLatest($criteria)
getPopular($criteria)
In tag model:
getPopular($criteria)
Now I’d like to create a method which would return all the articles for a particular tag so the code would look this I guess:
$tag=Tag::model()->with('articles')->together()->findByPk($tag_id);
return $tag->articles;
Now I really don’t know where to put this code, should it be inside Tag model available as $tag->getArticles() or maybe inside Article model as $article->getAllByTag(Tag & $tag). I’m not sure how to do this correctly. I think the Tag model should not return data from other models, however the Article model should not use any other models as well. I’m really confused here.
I’d love to hear someone’s with rich MVC experience take on this topic.