/*
Build the document as an array, but don't save it to the db.

@param array $overrides field => value pairs which override the defaults for this blueprint
@param array $associated [name] => [Association] pairs
@return array the document
432896
public function build($overrides = array(), $associated = array()) {
        $data = $this->_defaults;
        if($associated) {
            foreach($associated as $name => $document) {
                if(!isset($this->_associations[$name])) {
                    throw new \Exception("No association '$name' defined");
                }

                $association = $this->_associations[$name];

                if(!$association instanceof Association\EmbedsMany &&
                   !$association instanceof Association\EmbedsOne) {
                    throw new \Exception("Invalid association object for '$name'");
                }

                $overrides[$name] = $document;
            }
        }

        $this->_evalSequence($data);

        if($overrides) {
            foreach($overrides as $field => $value) {
                $data[$field] = $value;
            }
        }

        return $data;
    }
714265
def load_associated_collections
      array = association_fields

      if array.map{|f| f.collection_loaded?}.include?(false)
        StorageRoom.log("Fetching associated collections for '#{name}'")
        array.each{|f| f.collection}
      end
    end
762950
protected function _scaffoldFields(array $associations = [])
    {
        $action = $this->_action();
        $scaffoldFields = (array)$action->getConfig('scaffold.fields');
        if (!empty($scaffoldFields)) {
            $scaffoldFields = Hash::normalize($scaffoldFields);
        }

        if (empty($scaffoldFields) || $action->getConfig('scaffold.autoFields')) {
            $cols = $this->_table()->getSchema()->columns();
            $cols = Hash::normalize($cols);

            $scope = $action->getConfig('scope');
            if ($scope === 'entity' && !empty($associations['manyToMany'])) {
                foreach ($associations['manyToMany'] as $alias => $options) {
                    $cols[sprintf('%s._ids', $options['entities'])] = [
                        'multiple' => true
                    ];
                }
            }

            $scaffoldFields = array_merge($cols, $scaffoldFields);
        }

        // Check for blacklisted fields
        $blacklist = $action->getConfig('scaffold.fields_blacklist');
        if (!empty($blacklist)) {
            $scaffoldFields = array_diff_key($scaffoldFields, array_combine($blacklist, $blacklist));
        }

        // Make sure all array values are an array
        foreach ($scaffoldFields as $field => $options) {
            if (!is_array($options)) {
                $scaffoldFields[$field] = (array)$options;
            }

            $scaffoldFields[$field] += ['formatter' => null];
        }

        $fieldSettings = $action->getConfig('scaffold.field_settings');
        if (empty($fieldSettings)) {
            $fieldSettings = [];
        }
        $fieldSettings = array_intersect_key($fieldSettings, $scaffoldFields);
        $scaffoldFields = Hash::merge($scaffoldFields, $fieldSettings);

        return $scaffoldFields;
    }
731744
public function listAction(array $override = [])
    {
        $demand = $this->createDemandFromSettings();

        if (!empty($override) && $this->settings['allowOverride']) {
            $this->overrideDemand($demand, $override);
        }

        if ($demand->getSingleRecords()) {
            $addresses = $this->addressRepository->getAddressesByCustomSorting($demand);
        } else {
            $addresses = $this->addressRepository->findByDemand($demand);
        }

        $this->view->assignMultiple([
            'demand' => $demand,
            'addresses' => $addresses
        ]);

        CacheUtility::addCacheTagsByAddressRecords(
            $addresses instanceof QueryResultInterface ? $addresses->toArray() : $addresses
        );
    }
1342156
public function getParams(array $overrides = null) {
        $params = array(
            'token' => $this->_token,
            'channel' => $this->_channel,
            'icon_emoji' => $this->_icon_emoji,
            'username' => $this->_username
        );

        if ($overrides) {
            $params = array_merge($params, $overrides);
        }

        return $params;
    }
950525
public function config($key = null, $value = null, $override = false)
    {
        if (is_array($key) && is_bool($value)) {
            $override = $value;
        }

        return Util::operateArray($this->config, $key, $value, null, null, $override);
    }
1126674
public static function bulkInsert($documents)
    {
        $instance = new static();

        $autoIncrementField = $instance->getAutoIncrementField();
        $allowNull = $instance->isAllowNullValue();
        $fieldTypes = $instance->getFieldTypes();
        foreach ($documents as $i => $document) {
            if ($autoIncrementField && !isset($document[$autoIncrementField])) {
                $document[$autoIncrementField] = $instance->getNextAutoIncrementId();
            }
            foreach ((array)$fieldTypes as $field => $type) {
                if (isset($document[$field])) {
                    $document[$field] = $instance->normalizeValue($type, $document[$field]);
                } elseif ($field !== '_id') {
                    $document[$field] = $allowNull ? null : $instance->normalizeValue($type, '');
                }
            }
            $documents[$i] = $document;
        }

        return $instance->getConnection()->bulkInsert($instance->getSource(), $documents);
    }
949782
public function getActionsOptions($override = false)
    {
        //make sure we only run this once and then return the cached version
        if (empty($this->actionsOptions) || $override) {
            $this->actionsOptions = array();

            //loop over the actions to build the list
            foreach ($this->getActions($override) as $name => $action) {
                $this->actionsOptions[] = $action->getOptions(true);
            }
        }

        return $this->actionsOptions;
    }
517623
public function setOverrides($overrides)
    {
        $fieldsOverridden = [];
        if (isset($this->payload->body)) {
            foreach ($this->payload->body as &$field) {
                if (
                    isset($field->overridable)
                    && true === $field->overridable
                    && isset($field->key)
                    && isset($overrides[$field->key])
                    && null !== $overrides[$field->key]
                ) {
                    $field->value                  = $overrides[$field->key];
                    $fieldsOverridden[$field->key] = $overrides[$field->key];
                }
            }
        }
        if ($fieldsOverridden) {
            $this->setLogs($fieldsOverridden, 'fieldsOverridden');
        }

        return $this;
    }
1095043
public function getEditFieldsArrays($override = false)
    {
        $return = array();

        foreach ($this->getEditFields(true, $override) as $fieldObject) {
            $return[$fieldObject->getOption('field_name')] = $fieldObject->getOptions();
        }

        //get the key field if this is a model page
        if ($this->config->getType() === 'model') {
            $this->fillKeyField($return);
        }

        return $return;
    }
759835
def _association(args, default_options={})
      return if options.nil?

      options = args.first

      if options.is_a?(Hash)
        options     = {}.merge(options)
        name        = options.keys.first
        properties  = options.delete(name)

        @associations[name] = default_options.merge({ :include => properties }).merge(options)
      elsif options.is_a?(Array)
        options.each do |option|
          association option
        end
      else
        @associations[options] = args[1] || {}
      end
    end
119915
private function attachPropertyOverrides(
        array $classAnnotations,
        ReflectionClass $reflectionClass,
        Mapping\ClassMetadata $metadata,
        Mapping\ClassMetadataBuildingContext $metadataBuildingContext
    ) : void {
        // Evaluate AssociationOverrides annotation
        if (isset($classAnnotations[Annotation\AssociationOverrides::class])) {
            $associationOverridesAnnot = $classAnnotations[Annotation\AssociationOverrides::class];

            foreach ($associationOverridesAnnot->value as $associationOverride) {
                $fieldName = $associationOverride->name;
                $property  = $metadata->getProperty($fieldName);

                if (! $property) {
                    throw Mapping\MappingException::invalidOverrideFieldName($metadata->getClassName(), $fieldName);
                }

                $existingClass = get_class($property);
                $override      = new $existingClass($fieldName);

                // Check for JoinColumn/JoinColumns annotations
                if ($associationOverride->joinColumns) {
                    $joinColumns = [];

                    foreach ($associationOverride->joinColumns as $joinColumnAnnot) {
                        $joinColumns[] = $this->convertJoinColumnAnnotationToJoinColumnMetadata($joinColumnAnnot);
                    }

                    $override->setJoinColumns($joinColumns);
                }

                // Check for JoinTable annotations
                if ($associationOverride->joinTable) {
                    $joinTableAnnot    = $associationOverride->joinTable;
                    $joinTableMetadata = $this->convertJoinTableAnnotationToJoinTableMetadata($joinTableAnnot);

                    $override->setJoinTable($joinTableMetadata);
                }

                // Check for inversedBy
                if ($associationOverride->inversedBy) {
                    $override->setInversedBy($associationOverride->inversedBy);
                }

                // Check for fetch
                if ($associationOverride->fetch) {
                    $override->setFetchMode(
                        constant(Mapping\FetchMode::class . '::' . $associationOverride->fetch)
                    );
                }

                $metadata->setPropertyOverride($override);
            }
        }

        // Evaluate AttributeOverrides annotation
        if (isset($classAnnotations[Annotation\AttributeOverrides::class])) {
            $attributeOverridesAnnot = $classAnnotations[Annotation\AttributeOverrides::class];

            foreach ($attributeOverridesAnnot->value as $attributeOverrideAnnot) {
                $fieldMetadata = $this->convertColumnAnnotationToFieldMetadata(
                    $attributeOverrideAnnot->column,
                    $attributeOverrideAnnot->name,
                    false
                );

                $metadata->setPropertyOverride($fieldMetadata);
            }
        }
    }
1147707
private function exportToMultiple(array $configurations, array $overrideData)
    {
        // Create export directory if it doesn't exist.
        if (!file_exists($this->path)) {
            mkdir($this->path, 2775, true);
        }

        foreach ($configurations as $dataTypeHandle => $configuration) {
            Schematic::info('Exporting '.$dataTypeHandle);
            foreach ($configuration as $recordName => $records) {
                // Check if there is data in the override file for the current record.
                if (isset($overrideData[$dataTypeHandle][$recordName])) {
                    $records = array_replace_recursive($records, $overrideData[$dataTypeHandle][$recordName]);
                }

                // Export records to file.
                $fileName = $this->toSafeFileName($dataTypeHandle.'.'.$recordName.'.yml');
                FileHelper::writeToFile($this->path.$fileName, Data::toYaml($records));
                Schematic::info('Exported '.$recordName.' to '.$fileName);
            }
        }
    }
703857
public function addEntity($entity, array $overrides = []): RssFeedItem
    {
        return $this->items[] = RssFeedItem::fromEntity($entity, $overrides);
    }
621503
public function visible($visible = [], $override = false)
    {
        $this->each(function ($model) use ($visible, $override) {
            /** @var Model $model */
            $model->visible($visible, $override);
        });

        return $this;
    }
1010561
final public function queryArrayValues(string $query, array $overrideTypes = [])
    {
        $recordset = $this->queryRecordset($query, '', [], $overrideTypes);
        if (false === $recordset) {
            return false;
        }

        $return = [];
        while (! $recordset->eof()) {
            $return[] = $recordset->values;
            $recordset->moveNext();
        }
        return $return;
    }
64331
public function collect($restrictToModules = array(), $mergeWithExisting = false)
    {
        $entitiesByModule = $this->getEntitiesByModule();

        // Resolve conflicts between duplicate keys across modules
        $entitiesByModule = $this->resolveDuplicateConflicts($entitiesByModule);

        // Optionally merge with existing master strings
        if ($mergeWithExisting) {
            $entitiesByModule = $this->mergeWithExisting($entitiesByModule);
        }

        // Restrict modules we update to just the specified ones (if any passed)
        if (!empty($restrictToModules)) {
            // Normalise module names
            $modules = array_filter(array_map(function ($name) {
                $module = ModuleLoader::inst()->getManifest()->getModule($name);
                return $module ? $module->getName() : null;
            }, $restrictToModules));
            // Remove modules
            foreach (array_diff(array_keys($entitiesByModule), $modules) as $module) {
                unset($entitiesByModule[$module]);
            }
        }
        return $entitiesByModule;
    }