2 Replies Latest reply on Aug 3, 2012 1:55 PM by Andrew Escutia

    Problem using update_attributes

    Val Palhories

      I am trying to update a model object but when I call update_attributes on the object it creates a new row in the database instead of updating the existing row.  The new row contains null in all fields except for the columns that I attempt to update through the update_attributes call.  Im viewing this through SQL Lite Studio.  On sequential update_attributes it will update the new row that shouldnt have been created.

       

      This is my model:

       

      class Message

        include Rhom::FixedSchema

       

        property :RowID, :long

        property :LastModifiedUserID, :long

        property :LastModifiedDateTime, :datetime

        property :ActiveIND, :bool

        property :MessageDateTime, :datetime

        property :MessageText, :string

        property :Subject, :string

        property :SenderUserID, :long

      end

       

       

      and this is how I am trying to access it:

       

      @message =  Message.find(:first, :conditions => {

                 'ActiveIND' => true

               })

              

      @message.update_attributes({"ActiveIND" => false})

        • Re: Problem using update_attributes
          Glenn Sayer

          Val,  are you sure your find is finding a true value?

            • Re: Problem using update_attributes

              We got it Glen, thanks for the response.

               

              Here's the exert from the google groups discussion

               

              I noticed in the database there is an extra column called 'object'.  I created a model object using the Create method, and was able to successfully call update_attributes on the object afterwards.  The data I am having problems with is data that i am receiving from a web service and performing an insert similar to as follows.  Can I not insert data into the db this way and then be able to use update_attributes?  This is a large amount of data and thought that this would be the quickest way to perform the insert.

               

              database = Rho::RHO.get_src_db(table_name)

               

              database.start_transaction

              jsonData.each do |row|

                   database.insert_into_table(table_name, row)

              end

              database.commit

               

              Got it.  I wasnt inserting a value into the object column.  I modified the insert to populate the object column with the primary key for the table.