Forum: Ruby on Rails Dynamic Finders with _or_create Don't Work?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6783a6831dbd3839a1f03b0f416c2c6f?d=identicon&s=25 Ian Harding (Guest)
on 2006-03-14 22:56
(Received via mailing list)
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:in
`method_missing'
        from (irb):5

I could swear this used to work.

- Ian
6783a6831dbd3839a1f03b0f416c2c6f?d=identicon&s=25 Ian Harding (Guest)
on 2006-03-16 15:28
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 Harding 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:in
> `method_missing'
>         from (irb):5
>
> I could swear this used to work.
>
> - Ian
This topic is locked and can not be replied to.