I have a straightforward relation between two models: Asset and Update.
both models (minus unrelated methods) here:
I ran into a problem where an Asset record will no longer update. For example a simple test:
a = Asset.first ; puts a.description; a.description = "new" ; a.save ; puts a.errors ; puts Asset.first.description
will generate:
"old" {} "old"
a.save returns true, a.errors is empty; but the change is not saved.
I went through every item in my Asset model to try to figure out what was causing it, and found that if I removed the ‘belongs_to :update’ relation, then everything worked fine.
But how a relation to another table, with no validations involved, could prevent the record from saving, is a mystery. (Plus if it was a validation problem then @asset.errors would not be empty on the save attempt.)
To make matters stranger, I decided to rename my Update model to Report model. With that, it worked. So maybe Update is a reserved name for a model (seems unlikely). But I don’t want to rename that model unless I have to (it’s too many places already), so I’m thinking there must be something else here that’s wrong or that I’m missing.
Any help is appreciated. Thanks.
Calling the association ‘update’ is a problem. To load the asset’s associated update, you would have to do this:
But update is an instance method that is already defined by ActiveRecord:
http://apidock.com/rails/ActiveRecord/Base/update