lib/inventory_refresh/inventory_object_lazy.rb
def skeletal_precreate!
      # Pre-create only for strategies that will be persisting data, i.e. are not saved already
      return if saved?
      # We can only do skeletal pre-create for primary index reference, since that is needed to create DB unique index
      # and full reference must be present
      return if !primary? || full_reference.blank?

      # To avoid pre-creating invalid records all fields of a primary key must have non null value
      # TODO(lsmola) for composite keys, it's still valid to have one of the keys nil, figure out how to allow this. We
      # will need to scan the DB for NOT NULL constraint and allow it based on that. So we would move this check to
      # saving code, but this will require bigger change, since having the column nil means we will have to batch it
      # smartly, since having nil means we will need to use different unique index for the upsert/update query.
      return if keys.any? { |x| full_reference[x].nil? }

      skeletal_primary_index.build(full_reference)
    end
def skeletal_precreate!
      # Pre-create only for strategies that will be persisting data, i.e. are not saved already
      return if saved?
      # We can only do skeletal pre-create for primary index reference, since that is needed to create DB unique index
      # and full reference must be present
      return if !primary? || full_reference.blank?

      # To avoid pre-creating invalid records all fields of a primary key must have non null value
      # TODO(lsmola) for composite keys, it's still valid to have one of the keys nil, figure out how to allow this. We
      # will need to scan the DB for NOT NULL constraint and allow it based on that. So we would move this check to
      # saving code, but this will require bigger change, since having the column nil means we will have to batch it
      # smartly, since having nil means we will need to use different unique index for the upsert/update query.
      return if keys.any? { |x| full_reference[x].nil? }

      skeletal_primary_index.build(full_reference)
    end
def skeletal_precreate! # Pre-create only for strategies that will be persisting data, i.e. are not saved already return if saved? # We can only do skeletal pre-create for primary index reference, since that is needed to create DB unique index # and full reference must be present return if ! primary? || full_reference . blank? # To avoid pre-creating invalid records all fields of a primary key must have non null value # TODO(lsmola) for composite keys, it's still valid to have one of the keys nil, figure out how to allow this. We # will need to scan the DB for NOT NULL constraint and allow it based on that. So we would move this check to # saving code, but this will require bigger change, since having the column nil means we will have to batch it # smartly, since having nil means we will need to use different unique index for the upsert/update query. return if keys . any? { | x | full_reference [ x ] . nil? } skeletal_primary_index . build ( full_reference ) end
Instead of loading the reference from the DB, we'll add the skeletal InventoryObject (having manager_ref and
 info from the default_values) to the correct InventoryCollection. Which will either be found in the DB or
 created as a skeletal object. The later refresh of the object will then fill the rest of the data, while not
 touching the reference.

 @return [InventoryRefresh::InventoryObject, NilClass] Returns pre-created InventoryObject or nil
Instead of loading the reference from the DB we ll add the skeletal InventoryObject ( having manager_ref and info from the default_values ) to the correct InventoryCollection . Which will either be found in the DB or created as a skeletal object . The later refresh of the object will then fill the rest of the data while not touching the reference .