modify
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user