0

I'm using Sequel ORM

@latestorder = Step.where(:tutorial_id =>data['tutorial_id']).order(Sequel.desc(:order)).limit(1) #data['tutorial_id'] is 1
@neworder = @latestorder[:order] +1; #<-- this line causes errors!

NoMethodError at /makenew/stepundefined method `+' for #<Step:0x2f85138>

Using .to_i does not work and I cannot use DB[] for this query.

Output of @latestorder and @latestorder[:order]

<?r @latestorder.inspect ?>

#

<?r @latestorder.each do |late| ?>
#{late.inspect}
<?r end ?>

#13, :user_id=>1, :tutorial_id=>1, :order=>9, :title=>"Choose a group", :instruction=>"From the groups page, choose one of the groups to go on. \r\n\r\nFor testing purposes if you have the password for flyasakite, choose the All About Compesh group", :url=>"http://compesh.com/groups", :datenumber=>"2012-11-10", :datetimenumber=>"2012-11-10 13:18"}>

<?r @latestorder.each do |late| ?>
#{late.order.inspect}
<?r end ?>

9

I need to be able to add 1 to the @latestorder that has a LIMIT of 1, without going inside an .each loop

desbest
  • 4,746
  • 11
  • 51
  • 84

3 Answers3

1

Your @latestorder is an array, get the first element, and try to use that:

@neworder = @latestorder[0][:order] +1;
Matzi
  • 13,770
  • 4
  • 33
  • 50
1

@latestorder is a Sequel::Dataset, if you want it to be a Hash, you need to change limit(1) to first.

Jeremy Evans
  • 11,959
  • 27
  • 26
0

Or because Sequel has different array/hash id's depending on the id of the row.

@neworder = @latestorder.first.order +1

desbest
  • 4,746
  • 11
  • 51
  • 84