Ruby on Rails Active Record Query

Kelvin

Employers and Jobs. Employers have many jobs. Jobs have a boolean field started.

I am trying to query and find a count for Employers that have more than one job that is started.

How do I do this?

Employer.first.jobs.where(started: true).count

Do I use a loop with a counter or is there a way I can do it with a query?

Thanks!

Naren Sisodiya

You can have condition on join

Employer.joins(:jobs).where(jobs: {started: true}).count

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Rails Active Record query with multiple optional params

分類Dev

Rails active record relationships

分類Dev

Sorting a Rails active record

分類Dev

Active Record Validation Rails 4

分類Dev

Table Join in Rails Active Record

分類Dev

Ruby on Rails `method_missing ':未定義のメソッドʻactive_record'

分類Dev

Ruby on Rails Active Record RANDOM()はループ内で常に同じ

分類Dev

Ruby on Rails / Active Record:カスタムソート順

分類Dev

Ruby on Rails / Active Record:カスタムソート順

分類Dev

Ruby on Rails + Active Record:1つのクエリで順序、明確、ランダム

分類Dev

Rails User.joins.not(...)in Active Record?

分類Dev

OR operator inside a Where Active Record Query

分類Dev

Rails Active Record find every 10th record

分類Dev

Ruby on Rails query limit in a range

分類Dev

Ruby on Rails - Database query in array

分類Dev

Ruby Active Record joins and includes generate different sql for count

分類Dev

Ruby graphql How to define object type which is not Active Record?

分類Dev

Ruby on Rails / Active Record / MYSQL-文字列属性によるグループ化と順序付け

分類Dev

how to validate uniqueness for custom scope active-record rails 4

分類Dev

How to get rails active record attributes corresponding SQL values

分類Dev

Rails Active Record Sorting using Concat w / nil値

分類Dev

Rails の高度な Active Record クエリ

分類Dev

Rails Active Recordの複雑なクエリ

分類Dev

Is there an equivalent to Ruby on Rails' to_query method in jQuery?

分類Dev

Ruby-on-Rails Model Naming Covention Query

分類Dev

Ruby on Rails Accessing attributes of record found using .last

分類Dev

Ruby on Rails-Active Recordを使用して同じオブジェクトが配列に表示される回数を知る方法は?

分類Dev

Ruby / Active Record:カスタムソート順

分類Dev

CodeIgniter COUNT with active record?

Related 関連記事

  1. 1

    Rails Active Record query with multiple optional params

  2. 2

    Rails active record relationships

  3. 3

    Sorting a Rails active record

  4. 4

    Active Record Validation Rails 4

  5. 5

    Table Join in Rails Active Record

  6. 6

    Ruby on Rails `method_missing ':未定義のメソッドʻactive_record'

  7. 7

    Ruby on Rails Active Record RANDOM()はループ内で常に同じ

  8. 8

    Ruby on Rails / Active Record:カスタムソート順

  9. 9

    Ruby on Rails / Active Record:カスタムソート順

  10. 10

    Ruby on Rails + Active Record:1つのクエリで順序、明確、ランダム

  11. 11

    Rails User.joins.not(...)in Active Record?

  12. 12

    OR operator inside a Where Active Record Query

  13. 13

    Rails Active Record find every 10th record

  14. 14

    Ruby on Rails query limit in a range

  15. 15

    Ruby on Rails - Database query in array

  16. 16

    Ruby Active Record joins and includes generate different sql for count

  17. 17

    Ruby graphql How to define object type which is not Active Record?

  18. 18

    Ruby on Rails / Active Record / MYSQL-文字列属性によるグループ化と順序付け

  19. 19

    how to validate uniqueness for custom scope active-record rails 4

  20. 20

    How to get rails active record attributes corresponding SQL values

  21. 21

    Rails Active Record Sorting using Concat w / nil値

  22. 22

    Rails の高度な Active Record クエリ

  23. 23

    Rails Active Recordの複雑なクエリ

  24. 24

    Is there an equivalent to Ruby on Rails' to_query method in jQuery?

  25. 25

    Ruby-on-Rails Model Naming Covention Query

  26. 26

    Ruby on Rails Accessing attributes of record found using .last

  27. 27

    Ruby on Rails-Active Recordを使用して同じオブジェクトが配列に表示される回数を知る方法は?

  28. 28

    Ruby / Active Record:カスタムソート順

  29. 29

    CodeIgniter COUNT with active record?

ホットタグ

アーカイブ