Materialize active record object with included associations

18 views
Skip to first unread message

Alexandru Calinoiu

unread,
Jul 2, 2015, 4:50:55 AM7/2/15
to rubyonra...@googlegroups.com
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,


Frederick Cheung

unread,
Jul 2, 2015, 8:58:32 AM7/2/15
to rubyonra...@googlegroups.com, calinoiu....@agilefreaks.com
to_a is the way to do this - why do you say this is impractical?

Fred 

Elizabeth McGurty

unread,
Jul 3, 2015, 8:29:28 AM7/3/15
to rubyonra...@googlegroups.com
Try
m = Movie.map(&:genders).includes(:genres)
Reply all
Reply to author
Forward
0 new messages