Materialize active record object with included associations

Hi

I have a basic active query like so:

m = Movie.includes(:genres)

m.genders is an CollectionProxy in this case. Is there a way I can
get
this as an array?

I know that calling to_a will do this, but this becomes impractical for
a
bunch of includes.

The problem that I am having is that when I cache m in redis after
fetching
it the genres query is done again if I don’t iterate the collection.

Regards,

On Thursday, July 2, 2015 at 9:50:55 AM UTC+1, Alexandru Calinoiu wrote:

m.genders is an CollectionProxy in this case. Is there a way I can
get this as an array?

I know that calling to_a will do this, but this becomes impractical for a
bunch of includes.

The problem that I am having is that when I cache m in redis after
fetching it the genres query is done again if I don’t iterate the
collection.

to_a is the way to do this - why do you say this is impractical?

Fred

Try
m = Movie.map(&:genders).includes(:genres)