Rails/ActiveRecord Sub collection

Posted by Jake on Stack Overflow See other posts from Stack Overflow or by Jake
Published on 2010-05-25T13:27:24Z Indexed on 2010/05/25 13:31 UTC
Read the original article Hit count: 509

Filed under:

I have three models: Store, Author, Books

Store has many Authors which has many Books.

What is the cleanest way to get a collection of all the books at the store?

This works:

@store.authors.collect{|a| a.books}.flatten 

Is there something in Active Record that I'm missing that makes this cleaner?

Jake

© Stack Overflow or respective owner

Related posts about ruby-on-rails