Add insert limit on many-to-many relation

Viewed 70

how do we add a limit to many-to-many relation. Following the example in the documentation let's say we have 3 tables post, category and post_category. Let's say I have a list of posts and on every post a possibility to choose a category.

How can I 'limit' the relation so that there can't be more then 5 categories per post and 100 posts per category?

I have managed to do so using a checking if count(post->books) < 5 on the create action of post_category controller but am looking for a way to do it more Yii friendly, if that exists.

Working on Yii 1.1.14.

1 Answers
Related