Beispiel #1
0
 /**
  * @param stdClass $parent
  * @param stdClass $child
  */
 private function handleRelation(stdClass $parent, stdClass $child)
 {
     $where = ['relatedKey' => $child->key];
     if ($child->as) {
         $where['as'] = $child->as;
     }
     $relation = Extras::findWhere($parent->Model->getDefinition()->getRelations(), $where);
     $missedErr = "Unable to find relation between '{$parent->Model->getUnique()}' " . "and '{$child->Model->getUnique()}', foreign key: '{$child->key}'.";
     $relation ?: Error::dropModelException($missedErr);
     $child->relation = $relation;
     $child->foreignKey = $relation->foreignKey;
     if ($relation->type === Extras::HAS_MANY) {
         $this->hasMany = true;
     }
     # Handle child `as`:
     if (!$child->as) {
         if ($relation->type === Extras::HAS_ONE || $relation->type === Extras::BELONGS_TO) {
             # On `hasOne`, `belongsTo`:
             $child->as = Inflector::singularize($child->Model->getTableName());
         } else {
             # On `hasMany`:
             $child->as = Inflector::pluralize($child->Model->getTableName());
         }
         $child->asProp = Inflector::camelize($child->as);
     } else {
         $child->asProp = $child->as;
     }
     # Handle child `prefix`:
     if (!$child->prefix) {
         $child->prefix = $parent->prefix ? $parent->prefix . Extras::GLUE_CHAR . $child->as : $child->as;
     }
 }
Beispiel #2
0
 /**
  * @return \Enjoin\Dialectify\Dialectify|null
  */
 public function dialectify()
 {
     if (!$this->Dialectify) {
         $map = ['mysql' => 'MySql', 'pgsql' => 'PostgreSql'];
         $driver = $this->connection()->getDriverName();
         isset($map[$driver]) ?: Error::dropModelException("Unknown dialectify driver: '{$driver}'!");
         $dialect = '\\Enjoin\\Dialectify\\' . $map[$driver];
         $this->Dialectify = new $dialect($this);
     }
     return $this->Dialectify;
 }