activerecord - Rails get last X objects with attribute match -


i have model deferredhost, has attribute ignore_flag. @ present, i'm getting of deferred hosts in controller:

@deferred_hosts = @company.deferred_hosts.last(5)

however, i'd make subjective , last 5 deferred hosts have ignore_flag = true.

how can go doing this? should use if statement , loop through each deferred host, or there more 'rails' way?

you can use where make query more specific:

@deferred_hosts = @company.deferred_hosts.where(ignore_flag: true).last(5) 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -