It looks rails automatically creates a "finder" method on models that have a "belongs_to". So I tried this in the console: c = Category.find(2) chunks = Chunk.find_by_category(c) chunks is always returned as an empty array. When I know have some chunks with a category_id of 2. Should the find_by_category do what I think it should be doing or am I completely off base? thanks, cott. ---------------------------------------------------------------------------------------------------- What''s an Intel chip doing in a Mac? A whole lor more that it''s ever done in a PC. My Digital Life - http://scottwalter.com/blog Pro:Blog - http://scottwalter.com/problog -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/d955f316/attachment-0003.html
First of all the find_by_xxx methods just return 1 record. I think the find_all_by_xxx is what you need. Does this work? chunks = Chunk.find_all_by_category_id(2) I''m not entirely sure the dynamic finders work with associations, but since "category_id" is a direct property of the model it shouldn''t have a problem with it. Might make a nice patch though. -Alex Scott Walter wrote:> It looks rails automatically creates a "finder" method on models that > have a "belongs_to". So I tried this in the console: > > c = Category.find(2) > chunks = Chunk.find_by_category(c) > > chunks is always returned as an empty array. When I know have some > chunks with a category_id of 2. > > Should the find_by_category do what I think it should be doing or am I > completely off base? > > thanks, cott. > > ---------------------------------------------------------------------------------------------------- > What''s an Intel chip doing in a Mac? A whole lor more that it''s ever done in a PC. > > My Digital Life - http://scottwalter.com/blog > Pro:Blog - http://scottwalter.com/problog > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/e12ca705/attachment-0001.html
yes that worked perfectly! thanks.
----------------------------------------------------------------------------------------------------
What''s an Intel chip doing in a Mac? A whole lor more that
it''s ever done in a PC.
My Digital Life - http://scottwalter.com/blog
Pro:Blog - http://scottwalter.com/problog
----- Original Message ----
From: Alex Wayne <alex@beautifulpixel.com>
To: rails@lists.rubyonrails.org
Sent: Thursday, April 13, 2006 12:23:51 AM
Subject: Re: [Rails] Automatic finder
First of all the find_by_xxx methods just return 1 record. I think the
find_all_by_xxx is what you need.
Does this work?
chunks = Chunk.find_all_by_category_id(2)
I''m not entirely sure the dynamic finders work with associations, but
since "category_id" is a direct property of the model it
shouldn''t have a problem with it. Might make a nice patch though.
-Alex
Scott Walter wrote: <!-- DIV {margin:0px} --> It looks rails
automatically creates a "finder" method on models that have a
"belongs_to". So I tried this in the console:
c = Category.find(2)
chunks = Chunk.find_by_category(c)
chunks is always returned as an empty array. When I know have some chunks with
a category_id of 2.
Should the find_by_category do what I think it should be doing or am I
completely off base?
thanks, cott.
----------------------------------------------------------------------------------------------------
What''s an Intel chip doing in a Mac? A whole lor more that
it''s ever done in a PC.
My Digital Life - http://scottwalter.com/blog
Pro:Blog - http://scottwalter.com/problog
_______________________________________________ Rails mailing list
Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/c737a73c/attachment.html