scientiffic
scientiffic

Reputation: 9415

combine activerecord query results

How can I combine results from two queries? For example, if I wanted to return both the first and last records for a model, how might I do this (the actual thing I want to do is more complicated, but uses the same premise). Here's what I've tried

Project.first & Project.last
Project.first + Project.last
Project.first.concat(Project.last)
Project.first.merge(Project.last)

Upvotes: 2

Views: 1125

Answers (1)

Adrian CB
Adrian CB

Reputation: 671

This question could be answered in a variety of ways (as it's a little ambiguous)...

I'm assuming though that you're after a traversable data structure, like an Array or a Hash (since you were using concat and merge).

Based on your example, potentially, the simplest solution is:

[Project.first, Project.last]

Upvotes: 3

Related Questions