rob
2007-Jul-18 17:38 UTC
Getting all records in a relationship - how can I do this in a cleaner way?
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 wrote that works fine, but it looks incredibly ugly and there has to be a "cleaner" way. Any ideas? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Jul-18 23:12 UTC
Re: Getting all records in a relationship - how can I do this in a cleaner way?
> 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 wrote that works fine, but it looks > incredibly ugly and there has to be a "cleaner" way. Any ideas?Graphic.find(:all, :include => [:themes => :categories], :conditions => ["categories.id = ?", params[:id]]) Or something close to that. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Matthew Rudy
2007-Jul-18 23:27 UTC
Re: Getting all records in a relationship - how can I do thi
you could alternatively define your category model as such class Category < ActiveRecord::Base has_many :themes has_many :graphics, :through => :themes end then; @category = Category.find(id, :include => :graphics) @graphics = @category.graphics. Philip Hallstrom 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 wrote that works fine, but it looks >> incredibly ugly and there has to be a "cleaner" way. Any ideas? > > Graphic.find(:all, :include => [:themes => :categories], > :conditions => ["categories.id = ?", params[:id]]) > > Or something close to that.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---