Dynamic Finders with _or_create Don't Work?


#1

What could cause this?

sdfl=PartNumber.find_by_part_number(“1111111”)
=> #<PartNumber:0xb78fc744 @attributes={“id”=>“11601”,
“part_number”=>“1111111”}>

sdfl=PartNumber.find_or_create_by_part_number(“1111111”)
NoMethodError: undefined method find_or_create_by_part_number' for PartNumber:Class from /usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/base.rb:942:inmethod_missing’
from (irb):5

I could swear this used to work.

  • Ian

#2

Anyone? This is kinda disturbing to me. Am I the only person who has
ever seen this? If the find_by works, shouldn’t the find_or_create_by
also at least try to work? My setup is plain vanilla. PartNumber only
has one attribute, part_number besides the id.

Ian H. wrote:

What could cause this?

sdfl=PartNumber.find_by_part_number(“1111111”)
=> #<PartNumber:0xb78fc744 @attributes={“id”=>“11601”,
“part_number”=>“1111111”}>

sdfl=PartNumber.find_or_create_by_part_number(“1111111”)
NoMethodError: undefined method find_or_create_by_part_number' for PartNumber:Class from /usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/base.rb:942:inmethod_missing’
from (irb):5

I could swear this used to work.

  • Ian