나는 레일 4를 사용하고 있으며 주어진 게시물에 대한 각 개별 게시물 검토 수를 얻고 싶습니다.관계를 통해 드릴 다운하여 카운트 받기
스키마 :
Post PostReview PostReviewVote
id post_id post_review_id
user_id user_id
voted_on_date
내가 좋아하는 뭔가가 있습니다
table.table.table-striped.table-hover
thead
tr
th Post Name
th Reviews Created For Post
th Total Votes in All Reviews For Post
tbody
- for post in @posts
tr
td= post.name
td= PostReview.where(post_id: post.id).size
td= PostReview.where(post_id: post.id).PostReviewVotes.size
을하지만 런타임 오류 인용 가져 오는 아니에요 :
undefined method `PostReviewVotes' for #<ActiveRecord::Relation []>
어떤 제안? 내 모델에는 적절한 연관성이 있습니다 (FYI).
그들은 적절한 연관성이 있다고합니다. 'Post'는'has_many : PostReviewVotes, through : PostReview'라는 연관성을 갖고 있습니까? – Beartech