What does it do if you add the local key to hasOne:
return $this->hasOne('App\Article', 'A_ID', 'A_ID');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So I have the following table structure
Storage Table

Article Table

Stock Table

My relations are defined as the following
class Article extends Model
{
protected $table = 'article';
protected $primaryKey = 'A_ID';
public $timestamps = false;
public function stock()
{
return $this->hasMany('App\Stock','A_ID');
}
}
class Storage extends Model
{
protected $table = 'storage';
protected $primaryKey = 'S_ID';
public $timestamps = false;
public function business()
{
return $this->belongsTo('App\Business','B_ID');
}
public function stock()
{
return $this->hasMany('App\Stock','S_ID');
}
}
class Stock extends Model
{
protected $table = 'stock';
protected $primaryKey = 'STO_ID';
public $timestamps = false;
public function storage()
{
return $this->belongsTo('App\Storage','S_ID');
}
public function article()
{
return $this->hasOne('App\Article','A_ID');
}
public function movement()
{
return $this->hasMany('App\StockMovement','STO_ID');
}
}
My problem is when i select the stock with the STO_ID = 2 and then access the article via $stock->article it returns the record for Metall even though the saved A_ID of 1 is Wood This only occurs to the second stock. The first stock with the id = 1 returns wood
Please or to participate in this conversation.