示例#1
0
 /**
  * Takes in an Registry and returns a ProjectState matching it.
  *
  * @param Registry $registry
  *
  * @return ProjectState
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public static function fromApps($registry)
 {
     $modelStates = [];
     foreach ($registry->getModels() as $modelName => $modelObj) {
         $modelStates[$modelName] = ModelState::fromModel($modelObj);
     }
     return static::createObject($modelStates);
 }
示例#2
0
文件: Meta.php 项目: eddmash/powerorm
 /**
  * {@inheritdoc}
  */
 public function getReverseRelatedObjects()
 {
     if (empty($this->_reverseRelationTreeCache)) {
         $allRelations = [];
         /* @var $model Model */
         /* @var $field RelatedField */
         $allModels = $this->registry->getModels(true);
         // collect all relation fields for this each model
         foreach ($allModels as $name => $model) {
             // just get the forward fields
             $fields = $model->meta->_getFields(['includeParents' => false, 'reverse' => false]);
             foreach ($fields as $field) {
                 if ($field->isRelation && $field->getRelatedModel() !== null) {
                     $allRelations[$field->relation->toModel->meta->modelName][$field->name] = $field;
                 }
             }
         }
         // set cache relation to models
         foreach ($allModels as $name => $model) {
             // get fields for each model
             $fields = isset($allRelations[$name]) ? $allRelations[$name] : [];
             $model->meta->_reverseRelationTreeCache = $fields;
         }
     }
     return $this->_reverseRelationTreeCache;
 }