Return last attribute's change

 This method may be slow and inefficient on model with lots of audit objects.
 Go through each audit in the reverse order and find the first occurrence when
 audit.modifications[attribute] changed
492834
def last_change_of(attribute)
      raise "#{attribute} is not audited for model #{self.class}. Audited attributes: #{self.class.audited_attributes}" unless self.class.audited_attributes.include? attribute.to_sym
      attribute = attribute.to_s # support symbol as well
      last = audits.size - 1
      last.downto(1) do |i|
        if audits[i].modifications[attribute] != audits[i-1].modifications[attribute]
          return audits[i].diff(audits[i-1])[attribute]
        end
      end
      nil
    end
730242
def previous_obj(self):
        
        previous_obj = None
        if self.previous_visit:
            try:
                previous_obj = self.model.objects.get(
                    **{f"{self.model.visit_model_attr()}": self.previous_visit}
                )
            except ObjectDoesNotExist:
                pass
        return previous_obj
1017546
function() {
				var changes = this._.attrChanges, orgVal;
				for ( var attr in changes ) {
					if ( changes.hasOwnProperty( attr ) ) {
						orgVal = changes[ attr ];
						// Restore original attribute.
						orgVal !== null ? this.setAttribute( attr, orgVal ) : this.removeAttribute( attr );
					}
				}
			}
739030
function() {
    for (var name in this.changes) {
      if (this.changes.hasOwnProperty(name)) {
        this.attributes[name] = this.changes[name][0]
      }
    }

    this.changes = {}
    return this
  }
97957
def changed(self):
        """"""
        return {key: value for key, value in six.iteritems(self)
                if getattr(self, key).changed}
123214
def attribute_changed(self):
        

        for model in umbra.ui.models.GraphModel.find_model(self):
            headers = model.horizontal_headers.values()
            if not self.name in headers:
                continue

            model.attribute_changed(model.find_node(self), headers.index(self.name))
        return True
443690
def last_modified(self):
        
        resource_list = self.traffic_incident()
        last_modified = namedtuple('last_modified', 'last_modified')
        if len(resource_list) == 1 and resource_list[0] is None:
            return None
        else:
            try:
                return [last_modified(resource['lastModified'])
                        for resource in resource_list]
            except (KeyError, TypeError):
                return [last_modified(resource['LastModifiedUTC'])
                        for resource in resource_list]
1075501
def audit_tag_with(tag)
      if audit = last_audit
        audit.update_attribute(:tag, tag)

        # Force the trigger of a reload if audited_version is used. Happens automatically otherwise
        audits.reload if self.class.audited_version
      else
        self.audit_tag = tag
        snap!
      end
    end
428805
def attribute_will_change!(attr)
      unless changed_attributes.key?(attr)
        changed_attributes[attr] = read_raw_attribute(attr).__deep_copy__
      end
    end
1289464
def nested_records_changed_for_autosave?
      self.class.reflect_on_all_autosave_associations.any? do |reflection|
        association = association_instance_get(reflection.name)
        association && Array.wrap(association.target).any? { |a| a.changed_for_autosave? }
      end
    end
1293476
def restore_last_revision!(id)
      record = restore_last_revision(id)
      if record
        record.store_revision do
          save_restorable_associations(record, revisionable_associations)
        end
      end
      return record
    end
569237
def prepare_revision
      return if new_record?
      if (respond_to?(:fragments_attributes_changed) && fragments_attributes_changed) ||
        !(changed & revision_fields).empty?
        self.revision_data = revision_fields.each_with_object({}) do |field, c|
          c[field] = send("#{field}_was")
        end
      end
    end
1303475
def _last(self, **spec):
        
        for record in self._entries(spec).order_by(orm.desc(model.Entry.local_date),
                                                   orm.desc(model.Entry.id))[:1]:
            return entry.Entry(record)
        return None
1315069
def versioned_changes
      modified_changes = {}
      raw_changes = self.changes.select {|k,_| versioned_attribute?(k)}.to_hash

      raw_changes.each do |key, (previous, current)|
        if reflection = self.class.reflect_on_association(key.to_sym)
          if reflection.collection?
            previous = previous.map(&:versioned_attributes)
            current  = current.map(&:versioned_attributes)
          else
            previous = previous ? previous.versioned_attributes : {}

            current  = if current && !current.marked_for_destruction?
              current.versioned_attributes
            else
              {}
            end
          end
        end

        # This really shouldn't need to be here,
        # but there is some confusion if we're destroying
        # an associated object in a save callback on the
        # parent object. We can't know that the callback
        # is going to destroy this object on save,
        # so we just have to add the association normally
        # and then filter it out here.
        if previous != current
          modified_changes[key] = [previous, current]
        end
      end

      modified_changes
    end
939801
def first_or_new(self, _attributes=None, **attributes):
        
        if _attributes is not None:
            attributes.update(_attributes)

        instance = self.where(attributes).first()

        if instance is None:
            instance = self._related.new_instance()
            instance.set_attribute(self.get_plain_foreign_key(), self.get_parent_key())

        return instance
651770
def changes(self):
        """"""
        obj = AuditLogChanges(self, self._changes)
        del self._changes
        return obj
710858
def error_in_changed_attributes?
      errs = errors

      changed_attributes.each_pair do |key, _|
        # If any of the fields with errors are also the ones that were
        return true if errs[key]
      end

      false
    end