What I am trying to do is the following:
Say we have a post that may have many questions and answers where both questions and answers belong to a given post. What I am trying to figure out is how to get the posts that have less than 5 questions and answers together.
something like:
@posts = Post.where(post.questions + post.answers < 5)
any suggestions?
You could create a new field on the table that would hold the sum of the questions and answers of a post. This could be done using a callback like this:
Then in your controller you could do
@posts = Post.where('sum < 5')