Jump to content
Larry Ullman's Book Forums

Normalization


Edward
 Share

Recommended Posts

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

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

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

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).

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...