Defines many to one association
172213
public function hasMany($model, $their_field = null, $our_field = null, $as_field = null)
    {
        if (!$our_field) {
            $our_field = $this->id_field;
        }
        if (!$their_field) {
            $their_field = ($this->table).'_id';
        }
        /** @type SQL_Many $rel */
        $rel = $this->add('SQL_Many', $as_field ?: $model);
        $rel->set($model, $their_field, $our_field);

        return $rel;
    }
401038
public void setAssociation(String collectionRole, Association association) {
		if ( associations == null ) {
			associations = new HashMap<>();
		}
		associations.put( collectionRole, association );
	}
970344
def _write_related_m2m_relations(self, obj, many_to_many_relationships):
        
        for fieldname, related_objs in many_to_many_relationships.items():
            # TODO On PATCH avoid clearing existing relationships not provided?
            setattr(obj, fieldname, related_objs)
1096107
def clone_has_one(old_object, new_object)
      old_object.class.reflect_on_all_associations(:has_one).each do |association|
        old_association = old_object.send(association.name)
        build_has_one(new_object, association, old_association) if build_has_one?(old_object, association)
      end

      new_object
    end
1176897
def map_relations
      self.resource_relations = {}
      model.alchemy_resource_relations.each do |name, options|
        name = name.to_s.gsub(/_id$/, '') # ensure that we don't have an id
        association = association_from_relation_name(name)
        foreign_key = association.options[:foreign_key] || "#{association.name}_id".to_sym
        resource_relations[foreign_key] = options.merge(model_association: association, name: name)
      end
    end
1288661
def associate(self, model):
        
        self._parent.set_attribute(self._foreign_key, model.get_attribute(self._other_key))

        return self._parent.set_relation(self._relation, model)
401802
public boolean isAssociation()
    {
        return persistenceAttribType.equals(PersistentAttributeType.MANY_TO_MANY)
                || persistenceAttribType.equals(PersistentAttributeType.MANY_TO_ONE)
                || persistenceAttribType.equals(PersistentAttributeType.ONE_TO_MANY)
                || persistenceAttribType.equals(PersistentAttributeType.ONE_TO_ONE);
    }
572501
def save_bt_association(assoc, version)
      assoc_version_args = {
        version_id: version.id,
        foreign_key_name: assoc.foreign_key
      }

      if assoc.options[:polymorphic]
        foreign_type = @record.send(assoc.foreign_type)
        if foreign_type && ::PaperTrail.request.enabled_for_model?(foreign_type.constantize)
          assoc_version_args[:foreign_key_id] = @record.send(assoc.foreign_key)
          assoc_version_args[:foreign_type] = foreign_type
        end
      elsif ::PaperTrail.request.enabled_for_model?(assoc.klass)
        assoc_version_args[:foreign_key_id] = @record.send(assoc.foreign_key)
        assoc_version_args[:foreign_type] = assoc.klass
      end

      if assoc_version_args.key?(:foreign_key_id)
        ::PaperTrail::VersionAssociation.create(assoc_version_args)
      end
    end
1213127
def store_many(self, sql, values):
        """"""
        cursor = self.get_cursor()
        cursor.executemany(sql, values)
        self.conn.commit()
920520
def validate_collection_association(reflection)
        if association = association_instance_get(reflection.name)
          if records = associated_records_to_validate_or_save(association, new_record?, reflection.options[:autosave])
            records.each_with_index { |record, index| association_valid?(reflection, record, index) }
          end
        end
      end
703316
def txn_storeAssociation(self, server_url, association):
        
        a = association
        self.db_set_assoc(
            server_url,
            a.handle,
            self.blobEncode(a.secret),
            a.issued,
            a.lifetime,
            a.assoc_type)
1104178
private function checkDefinitions(): void {
    // Add many to many stuff if necessary
    foreach($this->unchecked as $def) {
      foreach($def->many_to_many as $relation) {
        //echo "Processing many to many for {$def->name}\n";

        // Set up left keys
        $related = $this->defs[$relation->entity_left];

        if(empty($relation->id_left)) {
          //echo "Setting {$relation->alias_join} id_left to {$related->id->alias}\n";
          $relation->idLeft($related->id->alias);
        }

        if(empty($relation->key_left)) {
          //echo "Setting {$relation->alias_join} key_left to " . keyify($related->name) . "\n";
          $relation->keyLeft(keyify($related->name));
        }
        //

        // Set up right keys
        $related = $this->defs[$relation->entity_right];

        if(empty($relation->id_right)) {
          //echo "Setting {$relation->alias_join} id_right to {$related->id->alias}\n";
          $relation->idRight($related->id->alias);
        }

        if(empty($relation->key_right)) {
          //echo "Setting {$relation->alias_join} key_right to " . keyify($related->name) . "\n";
          $relation->keyRight(keyify($related->name));
        }
        //

        // Left side relations
        $related = $this->defs[$relation->entity_left];

        //echo "Adding {$related->name} hasManyThrough {$relation->alias_join} to {$relation->alias_right}\n";
        $related->hasManyThrough(pluralize($relation->alias_right), $relation->entity_join, $relation->entity_right)
          ->idLocal($relation->id_left)
          ->idForeign($relation->id_right)
          ->keyLocal($relation->key_left)
          ->keyForeign($relation->key_right)
        ;

        if(!array_key_exists($relation->alias_join, $def->has_many)) {
          //echo "Adding {$related->name} hasMany {$def->name}\n";
          $related->hasMany($relation->alias_join, $def->full_name)
            ->localKey  ($relation->id_left)
            ->foreignKey($relation->key_left)
          ;
        }

        if(!array_key_exists($relation->alias_left, $def->belongs_to)) {
          //echo "Adding {$def->name} belongsTo {$related->name}\n";
          $def->belongsTo($relation->alias_left, $related->full_name);
        }
        //

        // Right side relations
        $related = $this->defs[$relation->entity_right];

        //echo "Adding {$related->name} hasManyThrough {$relation->alias_join} to {$relation->alias_left}\n";
        $related->hasManyThrough(pluralize($relation->alias_left), $relation->entity_join, $relation->entity_left)
          ->idLocal($relation->id_right)
          ->idForeign($relation->id_left)
          ->keyLocal($relation->key_right)
          ->keyForeign($relation->key_left)
        ;

        if(!array_key_exists($relation->alias_join, $def->has_many)) {
          //echo "Adding {$related->name} hasMany {$def->name}\n";
          $related->hasMany($relation->alias_join, $def->full_name)
            ->localKey  ($relation->id_right)
            ->foreignKey($relation->key_right)
          ;
        }

        if(!array_key_exists($relation->alias_right, $def->belongs_to)) {
          //echo "Adding {$def->name} belongsTo {$related->name}\n";
          $def->belongsTo($relation->alias_right, $related->full_name);
        }
        //
      }
    }

    // Add has many stuff if necessary
    foreach($this->unchecked as $def) {
      foreach($def->has_many as $relation) {
        //echo "Processing has many for {$def->name}\n";

        $related = $this->defs[$relation->foreign_entity];

        if(empty($relation->local_key)) {
          //echo "Setting {$relation->alias} local_key to {$def->id->alias}\n";
          $relation->localKey($def->id->alias);
        }

        if(empty($relation->foreign_key)) {
          //echo "Setting {$relation->alias} foreign_key to " . keyify($related->name) . "\n";
          $relation->foreignKey(keyify($related->name));
        }
      }
    }

    // Add belongs to stuff if necessary
    foreach($this->unchecked as $def) {
      foreach($def->belongs_to as $relation) {
        //echo "Processing belongs to for {$def->name}\n";

        $related = $this->defs[$relation->foreign_entity];

        if(empty($relation->local_key)) {
          //echo "Setting {$relation->alias} local_key to " . keyify($related->name) . "\n";
          $relation->localKey(keyify($related->name));
        }

        if(empty($relation->foreign_key)) {
          //echo "Setting {$relation->alias} foreign_key to {$def->id->alias}\n";
          $relation->foreignKey($related->id->alias);
        }

        if(!array_key_exists($relation->local_key, $related->required)) {
          //echo "Adding {$def->name} column {$relation->local_key} of type {$related->id->type}\n";
          $def->required($relation->local_key, $related->id->type);
        }
      }
    }

    // We've checked everything in the queue.  Clear it out.
    $this->unchecked = [];
  }
763342
def monitor_association_changes(association)
      define_method "#{association}=" do |value|
        attribute_will_change!(association.to_s) if _association_will_change?(association, value)
        super(value)
      end

      ids = "#{association.to_s.singularize}_ids"

      define_method "#{ids}=" do |value|
        attribute_will_change!(association.to_s) if _ids_will_change?(ids, value)
        super(value)
      end

      define_method "#{association}_attributes=" do |value|
        attribute_will_change!(association.to_s) if _nested_attributes_will_change?(value)
        super(value)
      end

      [association, ids].each do |name|
        define_method "#{name}_change" do
          changes[name]
        end

        define_method "#{name}_changed?" do
          changes.has_key?(association.to_s)
        end

        define_method "#{name}_previously_changed?" do
          previous_changes.has_key?(association.to_s)
        end
      end
    end
1176862
def _init_associations(self, fin_anno):
        """"""
        ini = InitAssc(fin_anno, self.godag)
        # self.hdr = ini.flds
        self.id2gos = ini.id2gos
        return ini.nts
334690
async function _removeAssociation(
  ownerModel,
  ownerObject,
  childModel,
  childId,
  associationName,
  Log
) {
  let childObject = await childModel.findOne({ _id: childId })
  if (childObject) {
    let association = ownerModel.routeOptions.associations[associationName]
    let associationType = association.type
    if (associationType === 'ONE_MANY') {
      // EXPL: one-many associations are virtual, so only update the child reference
      // childObject[association.foreignField] = null; //TODO: set reference to null instead of deleting it?
      // EXPL: only delete the reference if the ids match
      if (
        childObject[association.foreignField] &&
        childObject[association.foreignField].toString() ===
          ownerObject._id.toString()
      ) {
        childObject[association.foreignField] = undefined
      }
      await childObject.save()
    } else if (associationType === 'MANY_MANY') {
      // EXPL: remove references from both models

      // EXPL: if linking models aren't embeded, just upsert the linking model collection
      let embedAssociation =
        association.embedAssociation === undefined
          ? config.embedAssociations
          : association.embedAssociation
      if (!embedAssociation) {
        const linkingModel = association.include.through
        let query = {}
        query[ownerModel.modelName] = ownerObject._id
        query[childModel.modelName] = childObject._id

        await linkingModel.findOneAndRemove(query)
      } else {
        // EXPL: remove the associated child from the owner
        let deleteChild = ownerObject[associationName].filter(child => {
          return (
            child[childModel.modelName].toString() ===
            childObject._id.toString()
          )
        })
        deleteChild = deleteChild[0]

        let index = ownerObject[associationName].indexOf(deleteChild)
        if (index > -1) {
          ownerObject[associationName].splice(index, 1)
        }

        // EXPL: get the child association name
        let childAssociation = {}
        let childAssociations = childModel.routeOptions.associations
        for (let childAssociationKey in childAssociations) {
          let association = childAssociations[childAssociationKey]
          if (association.model === ownerModel.modelName) {
            childAssociation = association
          }
        }
        let childAssociationName = childAssociation.include.as

        // EXPL: remove the associated owner from the child
        let deleteOwner = childObject[childAssociationName].filter(owner => {
          return (
            owner[ownerModel.modelName].toString() ===
            ownerObject._id.toString()
          )
        })
        deleteOwner = deleteOwner[0]

        index = childObject[childAssociationName].indexOf(deleteOwner)
        if (index > -1) {
          childObject[childAssociationName].splice(index, 1)
        }

        await Promise.all([
          ownerModel.findByIdAndUpdate(ownerObject._id, ownerObject, {
            runValidators: config.enableMongooseRunValidators
          }),
          childModel.findByIdAndUpdate(childObject._id, childObject, {
            runValidators: config.enableMongooseRunValidators
          })
        ])
      }
    } else if (associationType === '_MANY') {
      // EXPL: remove reference from owner model

      // EXPL: remove the associated child from the owner
      let deleteChild = ownerObject[associationName].filter(childId => {
        return childId.toString() === childObject._id.toString()
      })
      deleteChild = deleteChild[0]

      let index = ownerObject[associationName].indexOf(deleteChild)
      if (index > -1) {
        ownerObject[associationName].splice(index, 1)
      }

      await Promise.all([
        ownerModel.findByIdAndUpdate(ownerObject._id, ownerObject, {
          runValidators: config.enableMongooseRunValidators
        })
      ])
    } else {
      throw Boom.badRequest('Association type incorrectly defined.')
    }
  } else {
    throw Boom.notFound('Child object not found.')
  }
}
650176
def each_association( objectpath )
    begin
      @client.associators(objectpath).each do |assoc|
        yield assoc
      end
    rescue Sfcc::Cim::ErrorInvalidClass, Sfcc::Cim::ErrorInvalidNamespace
    end
  end
78753
def association(self, group_xid):
        
        association = {'groupXid': group_xid}
        self._indicator_data.setdefault('associatedGroups', []).append(association)