On 7/19/07, rob <rob-n9Q/XG8udXg@public.gmane.org>
wrote:>
>
> 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---