hasMany() public méthode

Define a one-to-many relationship.
public hasMany ( string $related, string $foreignKey = null, string $localKey = null ) : Illuminate\Database\Eloquent\Relations\HasMany
$related string
$foreignKey string
$localKey string
Résultat Illuminate\Database\Eloquent\Relations\HasMany
 /**
  * Define a one-to-many relationship.
  *
  * @param  string  $related
  * @param  string  $foreignKey
  * @param  string  $localKey
  * @return \Illuminate\Database\Eloquent\Relations\HasMany
  */
 public function hasMany($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::hasMany($related, $foreignKey, $localKey);
     }
     $foreignKey = $foreignKey ?: $this->getForeignKey();
     $instance = new $related();
     $localKey = $localKey ?: $this->getKeyName();
     return new HasMany($instance->newQuery(), $this, $foreignKey, $localKey);
 }
Exemple #2
0
 public function hasMany($related, $foreignKey = null, $localKey = null)
 {
     return parent::hasMany($related, $foreignKey, $this->isOracleModel ? strtolower($localKey) : $localKey);
 }
Exemple #3
0
 /**
  * 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\HasMany
  */
 public function hasMany($related, $foreignKey = null, $localKey = null, $locale = null)
 {
     $relation = $this->getHasOneOrManyCaller();
     if (!($specialType = $this->getCmsSpecialRelationType($relation))) {
         return parent::hasMany($related, $foreignKey, $localKey);
     }
     list($foreignKey, $fieldKey) = $this->getKeysForSpecialRelation($specialType, $foreignKey);
     $fieldId = $this->getCmsReferenceFieldId($relation);
     /** @var Builder $hasMany */
     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();
         $hasMany = new HasMany($instance->newQuery(), $this, $instance->getTable() . '.' . $foreignKey, $localKey, $fieldId, $specialType);
     } else {
         $hasMany = parent::hasMany($related, $foreignKey, $localKey);
     }
     // add field key for wheres
     $hasMany->where($fieldKey, $fieldId);
     // limit to selected locale, if translated
     if ($this->getCmsSpecialRelationTranslated($relation)) {
         if (is_null($locale)) {
             $locale = app()->getLocale();
         }
         $hasMany->where(config('pxlcms.translatable.locale_key'), $this->lookUpLanguageIdForLocale($locale));
     }
     return $hasMany;
 }