Greetings, Buck and Koz show put on a sesssion of do''s and don''t s at railsconf - an expression of the rails way vision - Helping us to clean up our code with smart coding practices http://onrails.org/articles/2007/05/20/railsconf-2007-day-4 During the session they reinforced we should associations instead of finders to clean up our code. ..and while demonstrating they left us with a line that read something like "Blog.find_all_by_author_id" - and I thought to myself. No, they must be wrong. Don''t associations have the same sugar? [I can''t remember the exact code, but a few of us thought the use of the syntax wasn''t quite free...] Can''t I do Blog.find_all_by_author(author) ? Banging on our laptops in the lunch space, it seems they don''t exist. Not for long. This is railsconf. FindByAssociation gives Active Record dynamic finders for associations. Find_by_association helps us by determining the join conditions, :includes required tables, and builds a where clause for our needs. #Before Post.find(:all, :conditions => ["tags.id = ?", tag.id], :include => :tags) #After. ahh. joy Post.find_all_by_tag(tag) write up: http://www.nnovation.ca/2007/6/4/rails-plugin- find_by_association Cheers, Jodi General Partner The nNovation Group inc. www.nnovation.ca/blog --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 4, 2007, at 9:38 PM, Jodi Showers wrote:> FindByAssociation gives Active Record dynamic finders for > associations. Find_by_association helps us by determining the join > conditions, :includes required tables, and builds a where clause > for our needs.Some months ago I saw a plugin that provides that feature, I think it was this one http://agilewebdevelopment.com/plugins/ dynamic_finders_with_belongs_to_names -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 4-Jun-07, at 3:44 PM, Xavier Noria wrote:> > On Jun 4, 2007, at 9:38 PM, Jodi Showers wrote: > >> FindByAssociation gives Active Record dynamic finders for >> associations. Find_by_association helps us by determining the join >> conditions, :includes required tables, and builds a where clause >> for our needs. > > Some months ago I saw a plugin that provides that feature, I think it > was this one > > http://agilewebdevelopment.com/plugins/ > dynamic_finders_with_belongs_to_names > > -- fxn >harump! In addition to belongs_to, find_by_assocations works will all other association types. Really cleans up references to join tables in has_many, and has_many :thtorugh''s (and has_and_belongs_to_many). thanx for the ref Xavier. Jodi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Awesome! Thanks, this is a feature that I have wished for many times. nathan On 6/4/07, Jodi Showers <jodi-BOB1p6JRLoAV+D8aMU/kSg@public.gmane.org> wrote:> > Greetings, > Buck and Koz show put on a sesssion of do''s and don''t s at railsconf - an > expression of the rails way vision - Helping us to clean up our code with > smart coding practices > > http://onrails.org/articles/2007/05/20/railsconf-2007-day-4 > > During the session they reinforced we should associations instead of > finders to clean up our code. > > ..and while demonstrating they left us with a line that read something > like "Blog.find_all_by_author_id" - and I thought to myself. No, they must > be wrong. Don''t associations have the same sugar? [I can''t remember the > exact code, but a few of us thought the use of the syntax wasn''t quite > free...] > > Can''t I do Blog.find_all_by_author(author) ? > > Banging on our laptops in the lunch space, it seems they don''t exist. > > Not for long. This is railsconf. > > FindByAssociation gives Active Record dynamic finders for associations. > Find_by_association helps us by determining the join conditions, :includes > required tables, and builds a where clause for our needs. > > #Before > Post.find(:all, :conditions => ["tags.id = ?", tag.id], :include => :tags) > > #After. ahh. joy > Post.find_all_by_tag(tag) > > write up: > http://www.nnovation.ca/2007/6/4/rails-plugin-find_by_association > > Cheers, > Jodi > General Partner > The nNovation Group inc. > www.nnovation.ca/blog > [image: ranting o the technology and business of software]<http://feeds.feedburner.com/on-innovation> > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---