# Is there a better way to get all of these records?

**URL:** <https://www.ruby-forum.com/t/is-there-a-better-way-to-get-all-of-these-records/109796>\
**Category:** Rails\
**Created:** [July 19, 2007, 4:00am UTC](https://www.ruby-forum.com/t/is-there-a-better-way-to-get-all-of-these-records/109796 "2007-07-19T04:00:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [July 19, 2007, 4:00am UTC](https://www.ruby-forum.com/t/is-there-a-better-way-to-get-all-of-these-records/109796/1 "2007-07-19T04:00:14Z")

</div>

[Parked at Loopia](http://pastie.caboo.se/79914) - i’d like to get all of the graphics of  
a certain _category_ (not theme) by specifying the category id, but  
none of the graphics are associated with a category\_id, just a  
theme\_id. i included a solution i came up with that works fine, but it  
seems kind of weird. anyone know of an alternative method/way to go  
about doing this?

rob

---

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [July 19, 2007, 4:11am UTC](https://www.ruby-forum.com/t/is-there-a-better-way-to-get-all-of-these-records/109796/2 "2007-07-19T04:11:15Z")

</div>

On 7/19/07, rob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [Parked at Loopia](http://pastie.caboo.se/79914) - i’d like to get all of the graphics of  
> a certain _category_ (not theme) by specifying the category id, but  
> none of the graphics are associated with a category\_id, just a  
> theme\_id. i included a solution i came up with that works fine, but it  
> seems kind of weird. anyone know of an alternative method/way to go  
> about doing this?
> 
> rob

Hi Rob

You can use a has\_many :through here to get the graphics

class Category \< AR:B  
has\_many :themes  
has\_many :graphics, :through =\> :themes  
end

class Theme \< AR:B  
has\_many :graphics  
end

class Graphic \< AR:B  
belongs\_to :theme  
end

Then you can get the graphics for a category like this  
@graphics = Category.find( params[:id] ).graphics

HTH  
Daniel
