Skip to content

Commit

Permalink
Merge pull request #32 from andela-iamadi/ft-add-comments-resource-to…
Browse files Browse the repository at this point in the history
…-question-and-answers

Add comment relationship to Question and Answer serializers
  • Loading branch information
0sc committed Feb 15, 2016
2 parents bb036ea + 7f53482 commit d1fe165
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/serializers/answer_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class AnswerSerializer < MainSerializer
attributes :question_id, :comments_count
attributes :question_id, :comments_count, :comments
has_many :comments
end
2 changes: 1 addition & 1 deletion app/serializers/question_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class QuestionSerializer < MainSerializer
attributes :title, :tags, :answers_count, :comments_count, :views

def attributes(*args)
class_eval { has_many :answers } if instance_options[:include_answers]
class_eval { has_many :comments; has_many :answers } if instance_options[:include_answers]
super
end

Expand Down

0 comments on commit d1fe165

Please sign in to comment.