App error: undefined method `update_attributes' for #<Array:0x4583618>

Hello,

I have a fixed Schema model and am trying to update a RHOM database row. I'm just trying to create a short little demo so the database structure may not make much sense. Please bare with me!

My model looks as follows:

class Item

  include Rhom::FixedSchema

  property :ServiceOrderID, :string

  property :ItemNumber, :string

  property :Description, :string

  property :QtyNeeded, :long

  property :QtyDelivered, :long

  index :by_ItemNumber, [:ItemNumber]

I have the following method:

def self.UpdateQtyOrdered (serviceorderid,itemnumber,qtydelivered)

      @item_row = Item.find(:all, :conditions =>{'ServiceOrderID'=>serviceorderid,'ItemNumber'=>itemnumber})

      if @item_row != nil

          @item_row.update_attributes({"QtyDelivered" => qtydelivered.to_i}) 

      end

end

I get the following when I inspect the @item_row variable from the Rhoelements debugger:

@item_row [{:source_id=>40003, :object=>"146036996298588.12", :ServiceOrderID=>"SR22343", :ItemNumber=>"Burn Aids:57010", :Description=>"Burn Jel Unit Pack", :QtyNeeded=>"8", :QtyDelivered=>"0"}]

The following is the log file entry:

I 08/18/2013 06:58:25:075 0000053c           HttpServer| Process URI: '/app/Order/markitemdelivered'

I 08/18/2013 06:58:25:075 0000053c                  APP| RHO serve: /app/Order/markitemdelivered

I 08/18/2013 06:58:25:075 0000053c                  APP| Params: {"itemnumber"=>"Bandaids:0204", "serviceorderid"=>"SR22343", "sitename"=>"Lunchroom Cabinet", "customername"=>"DCT Solutions Group", "qtydelivered"=>"9"}

I 08/18/2013 06:58:25:076 0000053c                  APP| App error: undefined method `update_attributes' for #<Array:0x4583618>

E:/WorkSpace/Demo-POD/app/Item/item.rb:47:in `UpdateQtyOrdered'

E:/WorkSpace/Demo-POD/app/Order/order_controller.rb:55:in `markitemdelivered'

C:/MotorolaRhoMobileSuite2.2.1.13/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.5.1.13/lib/framework/rho/rhocontroller.rb:104:in `serve'

C:/MotorolaRhoMobileSuite2.2.1.13/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.5.1.13/lib/framework/rho/rhoapplication.rb:248:in `serve'

C:/MotorolaRhoMobileSuite2.2.1.13/ruby/lib/ruby/gems/1.9.1/gems/rhodes-3.5.1.13/lib/framework/rho/rho.rb:883:in `serve'

I 08/18/2013 06:58:25:076 0000053c           HttpServer| GC Start.

I 08/18/2013 06:58:25:077 0000053c           HttpServer| GC End.

Note: If I perform the update via the following method it works just fine:

def self.UpdateQtyOrderedSQL (serviceorderid,itemnumber,qtydelivered)

      require_source("Item")   

      database = Rho::RHO.get_src_db("Item")

      sql = "UPDATE Item SET QtyDelivered = " + qtydelivered + " WHERE ItemNumber = '" + itemnumber.to_s + "'"    

      database.execute_sql(sql) 

end

I'm sure it's something stupid! What am I missing here? I really would like to get update_attributes working!!

Thanks.

--- Val

Mark Nongkhlaw
Can you first test with :    

Can you first test with :

      @item_row = Item.find(:first, :conditions =>{'ServiceOrderID'=>serviceorderid,'ItemNumber'=>itemnumber})

and

      if @item_row

instead of

  

      if @item_row != nil

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Val Palhories
Mark,If I don't use :all then

Mark,

If I don't use :all then I don't get an item so there's nothing to update!

This is my entire model. Am I doing something wrong?

#require 'BaseModel/BaseModel'

# The model has already been created by the framework, and extends Rhom::RhomObject

# You can add more methods here

class Item

  include Rhom::FixedSchema

  property :ServiceOrderID, :string

  property :ItemNumber, :string

  property :Description, :string

  property :QtyNeeded, :long

  property :QtyDelivered, :long

 

  index :by_ItemNumber, [:ItemNumber]

 

  def self.ResetDB()

    Item.delete_all()

    CreateItem("SR22343","Bandaids:0204","Plastic Strip 1'x3'- 50ct 40/cs **12010cs**",10,0)

    CreateItem("SR22343","Burn Aids:57010","Burn Jel Unit Pack",8,0)

    CreateItem("SR12345","Burn Aids:57011","Burn-Jel Unit Dose-25/Box",9,0)

    CreateItem("SR12345","Cotton/Gauze:0802","2'x5yds Gauze Wraps ea  **17080**",2,0)

    CreateItem("SR54321","Cotton/Gauze:0803","3'x5ydsGauze Wrap ea  **17081**",4,0)

    CreateItem("SR12345","First Aid:22312","TRIPLE ANTIBIOTIC 12CT",1,0)

    CreateItem("SR54321","First Aid:22335","Triple Antibiotic",6,0)

    CreateItem("SR54321","First Aid:223B","Bulk Triple 1152/cs",3,0)

  end 

       

  def self.GetItemsByServiceOrder(serviceorderid)

    return Item.find_all(:order => "ItemNumber",:conditions =>["ServiceOrderID LIKE '#{serviceorderid}' AND QtyNeeded <> QtyDelivered"])

  end

 

  def self.GetByNumber(serviceorderid,itemnumber)

      return Item.find(:all, :order => "ItemNumber",:conditions =>{'ServiceOrderID'=>serviceorderid,'ItemNumber'=>itemnumber})

  end

  def self.CreateItem(serviceorderid,itemnumber,description,qtyneeded,qtydelivered)

      save_item = Item.create({"ServiceOrderID"=>serviceorderid,

                                  "ItemNumber" => itemnumber,

                                  "Description"=> description,

                                  "QtyNeeded" => qtyneeded,

                                  "QtyDelivered" => qtydelivered}) 

  end

 

  def self.UpdateQtyOrdered (serviceorderid,itemnumber,qtydelivered)

      @item_row = Item.GetByNumber(serviceorderid,itemnumber)

      if @item_row

          @item_row.update_attributes({"QtyDelivered" => qtydelivered.to_i}) 

      end

  end

 

  def self.UpdateQtyOrderedSQL (serviceorderid,itemnumber,qtydelivered)

      require_source("Item")   

      database = Rho::RHO.get_src_db("Item")

      sql = "UPDATE Item SET QtyDelivered = " + qtydelivered + " WHERE ItemNumber = '" + itemnumber.to_s + "'"    

      database.execute_sql(sql) 

  end

end

--- Val

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Kutir Mobility
Can you try thisdef self

Can you try this

def self.UpdateQtyOrdered (serviceorderid,itemnumber,qtydelivered)

      @item_row = Item.find(:all, :conditions =>{'ServiceOrderID'=>serviceorderid,'ItemNumber'=>itemnumber})

      if @item_row != nil

       @item_row.each do |item_row|

            item_row.update_attributes({"QtyDelivered" => qtydelivered.to_i})

    end

      end

end

Visnupriya

Kutir Mobility

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Val Palhories
Hi Visnupriya,Sorry for

Hi Visnupriya,

Sorry for taking so long to respond, I was out of the office on other projects.

I tried your recommendation and I have the same problem. It just will not update.What is so friggin' difficult about what I'm trying to do? This is making no sense to me. I'm sure it's something tiny but I can't spot it! At this point, only SQL updates work. Any other suggestions?

Thanks.

--- Val

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Lars Burgess
That's strange, are you

That's strange, are you getting the same error or a different error now? 

I agree with Kutir's suggestion because the problem was you were effectively calling an instance method on an array, that would never have worked.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Val Palhories
Lars,No errors, just doesn't

Lars,

No errors, just doesn't actually write the entry to the table.

--- Val

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Lars Burgess
Can you set the loglevel to 0

Can you set the loglevel to 0 and add the log here?  Then we can see all of the sql statements that are executed.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Val Palhories
Well .... you're not going to

Well .... you're not going to believe this ...

I set the loglevel to 0 and low and behold, it started working. I swear that's all I did!  I think I'm slowly going crazy!!!

So ... everything works as expected now and I guess I no longer have an issue. Visnupriya's suggestion worked so I marked that as the answer.

Thanks to everyone who helped me with this. I really appreciate. Sorry it took so long to get back to everyone, got a million other priorities!

--- Val

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
Does it still work after

Does it still work after changing the log level back to default?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Val Palhories
Mark,Yes it does. --- Val

Mark,

Yes it does.

--- Val

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mark Nongkhlaw
Then IMHO, its got nothing to

Then IMHO, its got nothing to do with log level. Problem was elsewhere.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments