Skip to content

Commit

Permalink
Add relationship getters (laravel#26607)
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir authored and taylorotwell committed Nov 25, 2018
1 parent 5f6d9a4 commit 1ca55a1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,16 @@ public function getQualifiedRelatedPivotKeyName()
return $this->table.'.'.$this->relatedPivotKey;
}

/**
* Get the parent key for the relationship.
*
* @return string
*/
public function getParentKeyName()
{
return $this->parentKey;
}

/**
* Get the fully qualified parent key name for the relation.
*
Expand All @@ -1031,6 +1041,16 @@ public function getQualifiedParentKeyName()
return $this->parent->qualifyColumn($this->parentKey);
}

/**
* Get the related key for the relationship.
*
* @return string
*/
public function getRelatedKeyName()
{
return $this->relatedKey;
}

/**
* Get the intermediate table for the relationship.
*
Expand Down
40 changes: 40 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,16 @@ public function getQualifiedFarKeyName()
return $this->getQualifiedForeignKeyName();
}

/**
* Get the foreign key on the "through" model.
*
* @return string
*/
public function getFirstKeyName()
{
return $this->firstKey;
}

/**
* Get the qualified foreign key on the "through" model.
*
Expand All @@ -546,6 +556,16 @@ public function getQualifiedFirstKeyName()
return $this->throughParent->qualifyColumn($this->firstKey);
}

/**
* Get the foreign key on the related model.
*
* @return string
*/
public function getForeignKeyName()
{
return $this->secondKey;
}

/**
* Get the qualified foreign key on the related model.
*
Expand All @@ -556,6 +576,16 @@ public function getQualifiedForeignKeyName()
return $this->related->qualifyColumn($this->secondKey);
}

/**
* Get the local key on the far parent model.
*
* @return string
*/
public function getLocalKeyName()
{
return $this->localKey;
}

/**
* Get the qualified local key on the far parent model.
*
Expand All @@ -565,4 +595,14 @@ public function getQualifiedLocalKeyName()
{
return $this->farParent->qualifyColumn($this->localKey);
}

/**
* Get the local key on the intermediary model.
*
* @return string
*/
public function getSecondLocalKeyName()
{
return $this->secondLocalKey;
}
}
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,14 @@ public function getQualifiedForeignKeyName()
{
return $this->foreignKey;
}

/**
* Get the local key for the relationship.
*
* @return string
*/
public function getLocalKeyName()
{
return $this->localKey;
}
}
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ public function getMorphClass()
{
return $this->morphClass;
}

/**
* Get the indicator for a reverse relationship.
*
* @return bool
*/
public function getInverse()
{
return $this->inverse;
}
}

0 comments on commit 1ca55a1

Please sign in to comment.