def has_many_identities(assoc, options)
      fk =  options[:foreign_key] || :"#{model_name.to_s.underscore}_id"
      pk = primary_key
      other_model_name = options[:class_name] || assoc.to_s.singularize.camelize
      other_model = other_model_name.to_s.constantize

      # all children iterations
      has_many :"#{assoc}_iterations", class_name: other_model_name, foreign_key: fk

      # current children:
      # has_many assoc, options.merge(conditions: ["#{model.effective_to_column_sql} = :date", :date=>END_OF_TIME)]
      define_method assoc do
        send(:"#{assoc}_iterations").current
      end
      # children at some date
      define_method :"#{assoc}_at" do |date=nil|
        # has_many assoc, options.merge(conditions: [%{#{model.effective_from_column_sql}<=:date AND #{model.effective_to_column_sql}>:date}, :date=>model.effective_date(date)]
        send(:"#{assoc}_iterations").scoped.at(date) # scoped necessary here to avoid delegation to Array
      end

      # all children identities
      define_method :"#{assoc}_identities" do
        # send(:"#{assoc}_iterations").select("DISTINCT #{other_model.identity_column_sql}").order(other_model.identity_column_sql).pluck(:identity)
        # other_model.unscoped.where(fk=>send(pk)).identities
        send(:"#{assoc}_iterations").identities
      end

      # children identities at a date
      define_method :"#{assoc}_identities_at" do |date=nil|
        # send(:"#{assoc}_iterations_at", date).select("DISTINCT #{other_model.identity_column_sql}").order(other_model.identity_column_sql).pluck(:identity)
        # other_model.unscoped.where(fk=>send(pk)).identities_at(date)
        send(:"#{assoc}_iterations").identities_at(date)
      end

      # current children identities
      define_method :"#{assoc}_current_identities" do
        # send(assoc).select("DISTINCT #{other_model.identity_column_sql}").order(other_model.identity_column_sql).pluck(:identity)
        # other_model.unscoped.where(fk=>send(pk)).current_identities
        send(:"#{assoc}_iterations").current_identities
      end

    end
def has_many_identities(assoc, options)
      fk =  options[:foreign_key] || :"#{model_name.to_s.underscore}_id"
      pk = primary_key
      other_model_name = options[:class_name] || assoc.to_s.singularize.camelize
      other_model = other_model_name.to_s.constantize

      # all children iterations
      has_many :"#{assoc}_iterations", class_name: other_model_name, foreign_key: fk

      # current children:
      # has_many assoc, options.merge(conditions: ["#{model.effective_to_column_sql} = :date", :date=>END_OF_TIME)]
      define_method assoc do
        send(:"#{assoc}_iterations").current
      end
      # children at some date
      define_method :"#{assoc}_at" do |date=nil|
        # has_many assoc, options.merge(conditions: [%{#{model.effective_from_column_sql}<=:date AND #{model.effective_to_column_sql}>:date}, :date=>model.effective_date(date)]
        send(:"#{assoc}_iterations").scoped.at(date) # scoped necessary here to avoid delegation to Array
      end

      # all children identities
      define_method :"#{assoc}_identities" do
        # send(:"#{assoc}_iterations").select("DISTINCT #{other_model.identity_column_sql}").order(other_model.identity_column_sql).pluck(:identity)
        # other_model.unscoped.where(fk=>send(pk)).identities
        send(:"#{assoc}_iterations").identities
      end

      # children identities at a date
      define_method :"#{assoc}_identities_at" do |date=nil|
        # send(:"#{assoc}_iterations_at", date).select("DISTINCT #{other_model.identity_column_sql}").order(other_model.identity_column_sql).pluck(:identity)
        # other_model.unscoped.where(fk=>send(pk)).identities_at(date)
        send(:"#{assoc}_iterations").identities_at(date)
      end

      # current children identities
      define_method :"#{assoc}_current_identities" do
        # send(assoc).select("DISTINCT #{other_model.identity_column_sql}").order(other_model.identity_column_sql).pluck(:identity)
        # other_model.unscoped.where(fk=>send(pk)).current_identities
        send(:"#{assoc}_iterations").current_identities
      end

    end
Association to be used in a parent class which has children which have identities
 (the parent class is referenced by id and may not have identity)
 The inverse association should be belongs_to