wrong number of arguments (2 for 0) on first invocation, using bundler without rails

435 views
Skip to first unread message

Troy Kruthoff

unread,
Mar 21, 2012, 8:12:05 PM3/21/12
to Composite Keys for ActiveRecord
class AccountUser < ActiveRecord::Base
self.primary_keys :account_id,:user_id
end

console:


>> AccountUser.all
ArgumentError: wrong number of arguments (2 for 0)
/Users/troy/.rvm/gems/ruby-1.9.3-p0/gems/
composite_primary_keys-5.0.2/lib/composite_primary_keys/base.rb:10:in
`primary_keys'
/Users/troy/Projects/node6/wtf/api/models/accounts_users/
account_user.rb:3:in `<class:AccountUser>'
/Users/troy/Projects/node6/wtf/api/models/accounts_users/
account_user.rb:2:in `<top (required)>'
(ripl):2:in `<main>'
>> AccountUser.all
AccountUser Load (1.0ms) SELECT "account_users".* FROM
"account_users"
=> [#<AccountUser account_id: 1, user_id: "KrazyKrut", token:
"2190bef01b456a9b12d5b423c30ec706", roles: nil>, #<AccountUser
account_id: 1, user_id: "DieselGeek", token:
"22f63b58967197db64cf1fe4be5fd878", roles: nil>]


Any ideas? The first call to primary_keys always fails, but after
than everything is just dandy!

Thanks,

Troy

Lori M Olson

unread,
Mar 22, 2012, 10:33:31 PM3/22/12
to compos...@googlegroups.com
self.primary_keys= ?  When did that become the thing to use?  I've been using this gem since it first appeared, and it was always:

set_primary_keys [:account_id,:user_id]

Rhett Sutphin

unread,
Mar 23, 2012, 12:20:58 AM3/23/12
to compos...@googlegroups.com
Hi,

On Mar 22, 2012, at 9:33 PM, Lori M Olson wrote:

> self.primary_keys= ? When did that become the thing to use? I've been using this gem since it first appeared, and it was always:
>
> set_primary_keys [:account_id,:user_id]

ActiveRecord 3.2 deprecated[1]

set_primary_key :account_id

in favor of

self.primary_key = :account_id

CPK 5.0 permits[2] self.primary_keys= to follow this pattern.

>
> On Wednesday, March 21, 2012 6:12:05 PM UTC-6, Troy Kruthoff wrote:
> class AccountUser < ActiveRecord::Base
> self.primary_keys :account_id,:user_id
> end

So, Tony, you need to write:

self.primary_keys = [:account_id, :user_id]

(Note the '='.)

Ref: https://github.com/drnic/composite_primary_keys/blob/master/lib/composite_primary_keys/base.rb#L24

Rhett

[1]: http://guides.rubyonrails.org/3_2_release_notes.html#activerecord_deprecations
[2]: https://github.com/drnic/composite_primary_keys/blob/master/History.rdoc

>
> console:
>
>
> >> AccountUser.all
> ArgumentError: wrong number of arguments (2 for 0)
> /Users/troy/.rvm/gems/ruby-1.​9.3-p0/gems/
> composite_primary_keys-5.0.2/​lib/composite_primary_keys/​base.rb:10:in
> `primary_keys'
> /Users/troy/Projects/node6/​wtf/api/models/accounts_users/
> account_user.rb:3:in `<class:AccountUser>'
> /Users/troy/Projects/node6/​wtf/api/models/accounts_users/
> account_user.rb:2:in `<top (required)>'
> (ripl):2:in `<main>'
> >> AccountUser.all
> AccountUser Load (1.0ms) SELECT "account_users".* FROM
> "account_users"
> => [#<AccountUser account_id: 1, user_id: "KrazyKrut", token:
> "​2190bef01b456a9b12d5b423c30ec7​06", roles: nil>, #<AccountUser
> account_id: 1, user_id: "DieselGeek", token:
> "​22f63b58967197db64cf1fe4be5fd8​78", roles: nil>]
>
>
> Any ideas? The first call to primary_keys always fails, but after
> than everything is just dandy!
>
> Thanks,
>
> Troy
>

> --
> You received this message because you are subscribed to the Google Groups "Composite Keys for ActiveRecord" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/compositekeys/-/08wp-mB9iEcJ.
> To post to this group, send email to compos...@googlegroups.com.
> To unsubscribe from this group, send email to compositekey...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/compositekeys?hl=en.

Lori M Olson

unread,
Mar 23, 2012, 10:41:29 AM3/23/12
to compos...@googlegroups.com
Thanks, Rhett.  I was afraid I'd missed something.  But I haven't moved to 3.2 yet, so not so much ;-)

> To unsubscribe from this group, send email to compositekeys+unsubscribe@​googlegroups.com.

Reply all
Reply to author
Forward
0 new messages