Reputation: 4595
I have the following in my controller:
@registrations = Registration.where('id > 1000000000')
Event.unarchived.each do |event|
event.registrations.by_submitted.each do |reg|
@registrations << reg
end
end
There has to be a better way to do this. I've tried replacing the first line with:
@registrations = Registration.none
But when I do that, the final @registrations
variable always comes up with zero records.
What is the proper way to use the none
method here?
Upvotes: 1
Views: 102
Reputation: 54882
I would recommend you to do it this way:
registration_ids = []
Event.unarchived.each do |event|
registration_ids << event.registrations.by_submitted.pluck(:id)
end
@registrations = Registration.where(id: registration_ids.flatten)
Upvotes: 3