B
B
bismoney2015-11-27 10:41:06
Ruby on Rails
bismoney, 2015-11-27 10:41:06

How to make such a condition?

Hello friends.
Please advise how to implement something similar.
There is a sample

Post
          .order(created_at: :desc)
          .limit(10)

How to implement for example like this:
We count how many of these 10 with ff_id=2, and the resulting number needs to be minus these 10 with ff_id=2
As a result, for example, if out of these 10 c ff_id = 2 for example 3
Then you need somehow 10 - 3, but minus 3 with ff_id = 1
Please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N. Bekseitov, 2015-11-27
@bismoney

posts = Post.order(created_at: :desc).limit(10)
posts.size - posts.where(ff_id: 2).size

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question