Edward Posted January 20, 2013 Share Posted January 20, 2013 I have been checking our the Relational Active Record in the YiiFramework guide. http://www.yiiframew...en/database.arr I am a little confused about the ER Diagram, why do they have a tbl_post_category table when the could of just put the column category_id within the post table. As far as i see it even with the tbl_post_category you would still end up having repeated column values, so what is the point in that? Link to comment Share on other sites More sharing options...
Edward Posted January 20, 2013 Author Share Posted January 20, 2013 I think i have worked this out myself, if we don't have the intermediary table there is no way for Yii to be able to use Relational Active Record to connect a product to the category with the foreign key. The only way would be to write raw sql which is a waste of code since we have the Relational Active Record to do the work for us. Link to comment Share on other sites More sharing options...
Edward Posted January 21, 2013 Author Share Posted January 21, 2013 Looks like i have not worked this out, i am confused with the example in the definitive guide and am still debating on whether a post_category table would be required? I have setup the intermediary table but the problem is now how to access it with Active Record. This is similar to the Yii Book tbl_page_has_file database, how do we update this the Yii way? I can see in Yii that is a many to many relationship but with the category situation i have i only have one category per item so i ask again do we need the extra table? I will work on some other stuff now until someone comes up with a explanation. Link to comment Share on other sites More sharing options...
Larry Posted January 21, 2013 Share Posted January 21, 2013 If there's a one-to-many relationship, then that table wouldn't be required. For example, if each post could only be in a single category, then a category_id column in the posts table would be fine. That table is required for many-to-many relationships, as in each post could be in many categories (which is common in a blog). 1 Link to comment Share on other sites More sharing options...
Edward Posted January 21, 2013 Author Share Posted January 21, 2013 Thanks Larry i really appreciate your quick answer, i was stumped with that diagram on the Yii Website. I'll put the category ID in the items table that makes everything much easier. Once again thanks. Link to comment Share on other sites More sharing options...
Recommended Posts