Skip to content

Use Update Rather Than Save? #8

@philnorton

Description

@philnorton

Hey

Just a query ref:

def stamp!
if self.last_seen.to_i < (Time.now - 5.minutes).to_i
self.last_seen = DateTime.now
self.save!
end
end

This is causing validations (ie validates_presence_of) against the User model to fail when it's trying to perform the update for the last seen timestamp. Rather than saving here, can this not just make use of update_column so that validations etc aren't triggered?

def stamp! 
  self.update_column(:last_seen, DateTime.now) if self.last_seen.to_i < (Time.now - 5.minutes).to_i 
end 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions