Don't change the timestamp for returned models if it exists
kos1kov opened this issue · 0 comments
kos1kov commented
Hi, when we make import and pass custom created_at, updated_at, it's inserted into database correctly, but in the returned result we had value that is not equal to value in database because it's set up as Time.now
it works incorrect only when we pass custom timestamp parameters
Also in documentation described that "However, it is also possible to set just :created_at in specific records. In this case despite using timestamps: true, :created_at will be updated only in records where that field is nil."
proposed solution in PR
Example
users = []
users << User.new(name: "Name", created_at: 1.day.ago)
User.import(user)
user = users.first
user.created_at => Time.now
user.reload.created_at => 1.day.ago