I have a problem running find using composite primary keys. I have the
following models:
Code : - fold - unfold
- class Stat < ActiveRecord::Base
- set_primary_keys :user_id, :score_aspect
- belongs_to :user
Code : - fold - unfold
- class User < ActiveRecord::Base
- has_many :stats
Stat.find runs fine when it can find a stat. But it returns error
instead of “nil”, when it cannot find a stat.
Code : - fold - unfold
-
Stat.find(user, “valid_aspect”)
- => #<Stat id: 335580687, user_id: 1000, score_aspect:
“valid_aspect” . . .> -
Stat.find(user, “dfsdf”)
- ActiveRecord::RecordNotFound: Couldn’t find all Stats with IDs
([[#<User id: 1000, . . . “dfsdf”]])stats
.user_id
=1000 AND
stats
.score_aspect
=‘dfsdf’ - from
/opt/local/lib/ruby/gems/1.8/gems/composite_primary_keys-2.2.2/lib/composite_primary_keys/base.rb:296:in
`find_from_ids’ - from
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:616:in
`find’ - from (irb):41
I am using http://compositekeys.rubyforge.org/ . Please help. Thanks.
Developing with Rails 2.3.2; Ruby 1.8.7 (2009-04-08 patchlevel 160)
[powerpc-darwin9]