Im trying to update an sqlite table row(id, data columns) from rails console. All the models attributes are updating but when updating the id attribute of the model, nothing happens.
irb(main):023:0> r = Person.find(4)
=> #<Person id: 4, data: "threeplusone">
irb(main):024:0> r.update_attributes({:id=>5})
=> true
irb(main):025:0> r.save
=> true
Above prints true but when i inspect the sqlite db id is not updated to 5.
irb(main):026:0> r = Person.find(4)
=> #<Person id: 4, data: "threeplusone">
irb(main):027:0> r.update_attributes({:data=>'TRIplusone'})
=> true
irb(main):028:0> r.save
=> true
Above prints true and the data attribute is updating well.
And my model
class Person < ActiveRecord::Base
attr_accessor :id,:data
attr_accessible :id,:data
end
Thanks for any help.
Rails won’t let you update the
idattribute easily. You could execute the following SQL though, and it should work. (Also, when you use theupdate_attributes(...)method, you don’t need to call.saveafterward).