Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.7] Add relationship getters #26607

Merged
merged 1 commit into from
Nov 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}