def belongs_to_identity(assoc, options={})
      other_model = assoc.to_s.camelize.constantize
      fk = :"#{other_model.model_name.to_s.underscore}_identity"
      if defined?(@slowly_changing_columns)
        @slowly_changing_columns << [fk, other_model.identity_column_definition.last]
        @slowly_changing_indices << fk
      end
      if ActiveRecord::VERSION::MAJOR > 3
        belongs_to assoc, ->{ where "#{other_model.effective_to_column_sql()}=#{END_OF_TIME}" },
                   options.reverse_merge(foreign_key: fk, primary_key: IDENTITY_COLUMN)
      else
        belongs_to assoc, options.reverse_merge(
                            foreign_key: fk, primary_key: IDENTITY_COLUMN,
                            conditions: "#{other_model.effective_to_column_sql()}=#{END_OF_TIME}"
                          )
      end
      define_method :"#{assoc}_at" do |date=nil|
        other_model.at(date).where(IDENTITY_COLUMN=>send(fk)).first
      end
    end
def belongs_to_identity(assoc, options={})
      other_model = assoc.to_s.camelize.constantize
      fk = :"#{other_model.model_name.to_s.underscore}_identity"
      if defined?(@slowly_changing_columns)
        @slowly_changing_columns << [fk, other_model.identity_column_definition.last]
        @slowly_changing_indices << fk
      end
      if ActiveRecord::VERSION::MAJOR > 3
        belongs_to assoc, ->{ where "#{other_model.effective_to_column_sql()}=#{END_OF_TIME}" },
                   options.reverse_merge(foreign_key: fk, primary_key: IDENTITY_COLUMN)
      else
        belongs_to assoc, options.reverse_merge(
                            foreign_key: fk, primary_key: IDENTITY_COLUMN,
                            conditions: "#{other_model.effective_to_column_sql()}=#{END_OF_TIME}"
                          )
      end
      define_method :"#{assoc}_at" do |date=nil|
        other_model.at(date).where(IDENTITY_COLUMN=>send(fk)).first
      end
    end
Association to be used in a child which belongs to a parent which has identity
 (the identity is used for the association rather than the id).
 The inverse assocation should be has_many_through_identity.