Populates the relations of the given object.

@param DataObject $object
@param array $data
@param array $fixtures

@return DataObject
519436
public function populateRelations(DataObject $object, $data, $fixtures)
    {
        // Populate Default Relations:
        
        $this->populateDefaultRelations($object);
        
        // Populate Relations:
        
        foreach ($data as $name => $value) {
            
            // Skip Object Identifiers:
            
            if ($this->isObject($object, $name)) {
                continue;
            }
            
            // Detect Relation:
            
            if ($this->isRelation($object, $name)) {
                
                if ($this->isHasOneRelation($object, $name)) {
                    
                    // Define Has-One Association:
                    
                    $this->verboseMessage(sprintf('%s is a has-one relation', $name));
                    
                    $this->populateOneRelation($object, $name, $value);
                    
                } elseif ($this->isHasManyRelation($object, $name) || $this->isManyManyRelation($object, $name)) {
                    
                    // Define Has-Many / Many-Many Association:
                    
                    $this->verboseMessage(sprintf('%s is a has-many/many-many relation', $name));
                    
                    $this->populateManyRelation($object, $name, $value);
                    
                }
                
            }
            
        }
        
        // Answer Object:
        
        return $object;
    }
284773
public static function populateResponseData(IResponse $response, &$dataObject): void
    {
        foreach (array_keys($response->data()) as $key) {
            $method = 'set';
            $method .= ucfirst(Str::camel($key));
            if (!method_exists($dataObject, $method)) {
                continue;
            }

            $dataObject->{$method}($response->{$key});
        }
    }
687890
public function setSchema(array $data)
    {
        foreach ($data as $tableData) {
            $this->tables[$tableData['name']] = (new Table($tableData['name']))
                        ->setPrimaryKey($tableData['pkey'])
                        ->setComment($tableData['comment'])
                        ->addColumns($tableData['columns']);
        }
        foreach ($data as $tableData) {
            $table = $this->definition($tableData['name']);
            foreach ($tableData['relations'] as $relationName => $relationData) {
                $relationData['table'] = $this->definition($relationData['table']);
                if ($relationData['pivot']) {
                    $relationData['pivot'] = $this->definition($relationData['pivot']);
                }
                $table->addRelation(new TableRelation(
                    $relationData['name'],
                    $relationData['table'],
                    $relationData['keymap'],
                    $relationData['many'],
                    $relationData['pivot'] ?? null,
                    $relationData['pivot_keymap'],
                    $relationData['sql'],
                    $relationData['par']
                ));
            }
        }
        return $this;
    }
1265095
private function populateObjectItems($object, array $definition)
    {
        $output = clone $object;
        foreach ($definition as $key => $node) {
            if (isset($node['required'])) {
                if ((!$node['required']) && (!isset($output->{$key}))) {
                    $output->{$key} = $node['default'];
                }
            } else {
                if (!isset($output->{$key})) {
                    $output->{$key} = new stdClass();
                }
                $output->{$key} = $this->populateObjectItems($output->{$key}, $node);
            }
        }
        return $output;
    }
961077
public function hydrate(array $data, $object)
    {
        $object->setId($this->getData('id', $data));
        $object->setName($this->getData('name', $data));
        return $object;
    }
1107303
public function isRelation(DataObject $object, $name)
    {
        return (
            $this->isHasOneRelation($object, $name) ||
            $this->isHasManyRelation($object, $name) ||
            $this->isManyManyRelation($object, $name)
        );
    }
637230
public function setFixtures($table, $fixtures, $generator = null, $baseIndex = 0)
    {
        $loading = $this->currentSession->into($table);
        if ($generator) {
            $loading = $loading->with($generator);
        }
        return $loading->load($fixtures, $baseIndex);
    }
1011286
public function hydrate(array $data, $object)
    {
        if (! $object instanceof Entity) {
            return $object;
        }
                
        parent::hydrate($data, $object);
               
        $authEntity = parent::hydrate($data, new \Pacificnm\Auth\Entity\Entity());
        
        $object->setAuthEntity($authEntity);
        
        $aclRoleEntity = parent::hydrate($data, new \Pacificnm\AclRole\Entity\Entity());
        
        $object->getAuthEntity()->setAclRoleEntity($aclRoleEntity);
        
        return $object;
    }
205627
public function addDataFixtures(array $fixturesPaths): Descriptor
    {
        if (!empty($fixturesPaths)) {
            foreach ($fixturesPaths as $path) {
                $this->dataFixtures->add($path);
            }
        }

        return $this;
    }
646921
public function populate($object, array $data)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('The first param should be a object.');
        }

        if ($object instanceof Array2ObjectInterface) {
            $object->__populate($data);
        } else {
            //this static cache is helpful when populate
            //many objects of the same type in a loop
            static $matcherCache = [];
            static $writerCache = [];

            $objectClass = get_class($object);
            $properties = Utils::getClassProperties($objectClass);
            foreach ($properties as $property) {
                //save in cache if the property is writable
                $writableCacheHash = $objectClass.$property->getName();
                if (!isset($writerCache[$writableCacheHash])) {
                    $writerCache[$writableCacheHash] = $this->context->getWriter()->isWritable($object, $property->getName());
                }
                foreach ($data as $key => $value) {
                    //save in cache if the property name match with key
                    $propHash = $objectClass.$property->getName().$key;
                    if (!isset($matcherCache[$propHash])) {
                        $matcherCache[$propHash] = $this->context->getMatcher()->match($property, $key);
                    }

                    if ($writerCache[$writableCacheHash] && $matcherCache[$propHash]) {
                        $types = Utils::getPropertyTypes($property);
                        $value = $this->parseValue($value, $types, $property, $object);
                        $this->context->getWriter()->setValue($object, $property->getName(), $value);
                    }
                }
            }
        }
    }
241538
public function addObject(DataObject $object)
    {
        if (!$this->isInDB()) {
            throw new BadMethodCallException("ChangeSet must be saved before adding items");
        }

        if (!$object->isInDB()) {
            throw new BadMethodCallException("Items must be saved before adding to a changeset");
        }

        $references = [
            'ObjectID' => $object->ID,
            'ObjectClass' => $object->baseClass(),
        ];

        // Get existing item in case already added
        $item = $this->Changes()->filter($references)->first();

        if (!$item) {
            $item = new ChangeSetItem($references);
            $this->Changes()->add($item);
        }

        $item->ReferencedBy()->removeAll();

        $item->Added = ChangeSetItem::EXPLICITLY;
        $item->write();

        $this->sync();
    }
485552
public static function unserialize($object, array $data)
    {
        $serializer = new static();
        $serializer->references = $data['@references'] ?? [];
        unset($data['@references']);

        return $serializer->unserializeObject($object, $data);
    }
263305
public static function PrepareUserObject($data_sent, $object) {
        foreach ($data_sent as $key => $value) {
            $method = "set" . ucfirst($key);
            $object->$method(!array_key_exists($key, $data_sent) ? null : $value);
        }
        return $object;
    }
1270943
protected function outputFixtures(InputInterface $input, OutputInterface $output, $fixtures)
    {
        $output->writeln(
            sprintf(
                'List of "%s" data fixtures ...',
                $this->getTypeOfFixtures($input)
            )
        );
        foreach ($fixtures as $fixture) {
            $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', get_class($fixture)));
        }
    }
1360566
protected function runHandler($object, $data = null)
    {
        /** @var ITypedObject $object */
        /** @var ArrayDataObject $data */
        $input = $data->getArray();

        if ($this->dataSource instanceof IValueObjectCollection) {
            /** @var IValueObject $object */
            /** @var IValueObject $newObject */
            $newObject = $this->form->createNewObjectFromInput($input);

            $this->form->invokeBeforeSubmitCallbacks($newObject, $input);
            $this->form->bindToObject($newObject, $input);
            $this->form->invokeOnSubmitCallbacks($newObject, $input);

            $this->dataSource->update($object, $newObject);

            $this->form->invokeOnSaveCallbacks($object, $input);

            return $newObject;
        } else {
            $this->form->invokeBeforeSubmitCallbacks($object, $input);
            $this->form->bindToObject($object, $input);
            $this->form->invokeOnSubmitCallbacks($object, $input);

            $this->dataSource->save($object);

            $this->form->invokeOnSaveCallbacks($object, $input);

            return $object;
        }
    }
1336884
public function loadFrom(DataObjectInterface $record)
    {
        $fieldName = $this->getName();
        if (empty($fieldName) || empty($record)) {
            return;
        }

        $relation = $record->hasMethod($fieldName)
            ? $record->$fieldName()
            : null;

        // Detect DB relation or field
        if ($relation instanceof Relation) {
            // Load ids from relation
            $value = array_values($relation->getIDList());
            parent::setValue($value);
        } elseif ($record->hasField($fieldName)) {
            // Load dataValue from field... a CSV for DBMultiEnum
            if ($record->obj($fieldName) instanceof DBMultiEnum) {
                $value = $this->csvDecode($record->$fieldName);

            // ... JSON-encoded string for other fields
            } else {
                $value = $this->stringDecode($record->$fieldName);
            }

            parent::setValue($value);
        }
    }
369145
public function hydrate($object, $data, $prefix)
    {
        if (is_array($data)) {
            foreach ($data as $key => $value) {
                // Check setMethod
     //           print_r(strrpos($key, $prefix));
                if (strrpos($key, $prefix) !== false && !$this->callSetter($object, $this->format($key, $prefix), $value)) {
                    // If no setter is defined, we reinject into array
                    $data[$key] = $value; // Change data with subObject
                }
            }
        }

        return $object;
    }