/** * Define a one-to-one relationship. * * @param string $related * @param string $foreignKey * @param string $localKey * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function hasOne($related, $foreignKey = null, $localKey = null) { // Check if it is a relation with an original model. if (!is_subclass_of($related, 'Jenssegers\\Mongodb\\Model')) { return parent::hasOne($related, $foreignKey, $localKey); } $foreignKey = $foreignKey ?: $this->getForeignKey(); $instance = new $related(); $localKey = $localKey ?: $this->getKeyName(); return new HasOne($instance->newQuery(), $this, $foreignKey, $localKey); }
public function hasOne($related, $foreignKey = null, $localKey = null) { return parent::hasOne($related, $foreignKey, $this->isOracleModel ? strtolower($localKey) : $localKey); }
/** * Overridden to catch special relationships to standard CMS models * * @param string $related * @param string $foreignKey * @param string $localKey * @param string $locale only used as an override, and only for ML images * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function hasOne($related, $foreignKey = null, $localKey = null, $locale = null) { $relation = $this->getHasOneOrManyCaller(); if (!($specialType = $this->getCmsSpecialRelationType($relation))) { return parent::hasOne($related, $foreignKey, $localKey); } list($foreignKey, $fieldKey) = $this->getKeysForSpecialRelation($specialType, $foreignKey); $fieldId = $this->getCmsReferenceFieldId($relation); // create the correct hasOne, for special relations that must save field_id values /** @var Builder $hasOne */ if ($specialType === static::RELATION_TYPE_CHECKBOX || $specialType === static::RELATION_TYPE_FILE || $specialType === static::RELATION_TYPE_IMAGE) { /** @var Model $instance */ $instance = new $related(); $localKey = $localKey ?: $this->getKeyName(); $hasOne = new HasOne($instance->newQuery(), $this, $instance->getTable() . '.' . $foreignKey, $localKey, $fieldId, $specialType); } else { $hasOne = parent::hasOne($related, $foreignKey, $localKey); } // add field key for wheres $hasOne->where($fieldKey, $fieldId); // limit to selected locale, if translated if ($this->getCmsSpecialRelationTranslated($relation)) { if (is_null($locale)) { $locale = app()->getLocale(); } $hasOne->where(config('pxlcms.translatable.locale_key'), $this->lookUpLanguageIdForLocale($locale)); } return $hasOne; }