문제

I'm starting with the Sequel database library for Ruby.

Given the following code:

require 'sequel'
db = Sequel.connect('sqlite://users.db')
users = db[:users]
users.first.delete

Ruby throws the error:

'delete' : wrong number of arguments (0 for 1) (ArgumentError)

I can delete multiple records, but .first.delete doesn't work. What's wrong?

도움이 되었습니까?

해결책

db[:users] gives you an Sequel::SQLite::Dataset. users.first method without any argument gives you a user as Hash object. Now you are calling Hash#delete, which required a argument. But you are not passing it that argument. Thus it is complaining.

Rather do as below :

# if you want to delete the the first matching argument of any specific
# attribute/db column
db[:users].filter(:key => 1).delete
# or if you want to delete the first record from db
db[:users].limit(1).delete

Read this #drop method also.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top