views:

81

answers:

1

Hello all,

Here is my Test model code:

require 'rubygems'
require 'composite_primary_keys'
class VamTest < ActiveRecord::Base
  set_table_name 'tests'
  set_primary_keys :service, :host
end

This is the stacktrace I get when I run the following:

>> VamTest.all
VamTest.all
ArgumentError: wrong # of arguments(0 for 1)
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1:in `class_eval'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2232:in `compute_type'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2230:in `compute_type'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1665:in `instantiate'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `collect!'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1578:in `find_every'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:618:in `find'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:638:in `all'
    from (irb):2
>> 

Check out the following:

>> VamTest.find(:first)
VamTest.find(:first)
ArgumentError: wrong # of arguments(0 for 2)
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1:in `class_eval'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2232:in `compute_type'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2230:in `compute_type'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1665:in `instantiate'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `collect!'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1578:in `find_every'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1535:in `find_initial'
    from C:/jruby/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:616:in `find'
    from (irb):31
>>

I get the feeling there is an issue with primary key definition in my model but i can't figure it out.

A: 

I suspect that naming your model Test is a source of trouble here. Open up the console and type Test. If it's actually finding your model you'll see something like this.

=> Testid: integer, service: string, host: string, created_at: datetime, updated_at: datetime

Although, my guess is that you're going to see this instead:

=> Test

Change your throw-away model to something like Foo and see how that goes.

jdl
jld,I tried typing Test into the console with no success, as in I got what you guessed:=> TestSo i went ahead and changed the name of the model, that worked! But then when I tried newModelName.find(:all) I got the same original error as when I was trying to Test.find(:all)
rafael
Could you please edit your question to include your new model, and the console output that you are seeing?
jdl
I just updated my question
rafael