This commit is contained in:
as2252258@163.com
2021-05-02 04:52:29 +08:00
parent d376042361
commit 1a11178875
+4 -12
View File
@@ -342,12 +342,10 @@ class ActiveRecord extends BaseActiveRecord
*/
public function hasOne(string $modelName, $foreignKey, $localKey): HasOne|ActiveQuery
{
if (!isset($this->attributes[$localKey])) {
if (($value = $this->getAttribute($localKey)) === null) {
throw new Exception("Need join table primary key.");
}
$value = $this->getAttribute($localKey);
$relation = $this->getRelation();
return new HasOne($modelName, $foreignKey, $value, $relation);
@@ -363,12 +361,10 @@ class ActiveRecord extends BaseActiveRecord
*/
public function hasCount($modelName, $foreignKey, $localKey): mixed
{
if (!isset($this->attributes[$localKey])) {
if (($value = $this->getAttribute($localKey)) === null) {
throw new Exception("Need join table primary key.");
}
$value = $this->getAttribute($localKey);
$relation = $this->getRelation();
return new HasCount($modelName, $foreignKey, $value, $relation);
@@ -384,12 +380,10 @@ class ActiveRecord extends BaseActiveRecord
*/
public function hasMany($modelName, $foreignKey, $localKey): mixed
{
if (!isset($this->attributes[$localKey])) {
if (($value = $this->getAttribute($localKey)) === null) {
throw new Exception("Need join table primary key.");
}
$value = $this->getAttribute($localKey);
$relation = $this->getRelation();
return new HasMany($modelName, $foreignKey, $value, $relation);
@@ -404,12 +398,10 @@ class ActiveRecord extends BaseActiveRecord
*/
public function hasIn($modelName, $foreignKey, $localKey): mixed
{
if (!isset($this->attributes[$localKey])) {
if (($value = $this->getAttribute($localKey)) === null) {
throw new Exception("Need join table primary key.");
}
$value = $this->getAttribute($localKey);
$relation = $this->getRelation();
return new HasMany($modelName, $foreignKey, $value, $relation);