문제

Let's pretend that we have two tables, Posts and Categories, that have a many to one relationship, one category to many posts. Which would be the best way to go about defining that in the class definitions?

  1. Just Category { has_many Posts }
  2. Just Post { belongs_to Category }
  3. Both Category { has_many Posts } AND Post { belongs_to Category }
도움이 되었습니까?

해결책

As you want to be able to do something like myCategory->Posts if you have a category, but also myPost->categories, you want to define both relations.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top