HadyElMaageny's avatar

Analogue\ORM store method

I'm using Analogue\ORM and trying to store an Impersonation entity with valid impersonator_id and target_id, but both IDs are always saved as 0 in the database. Here's my model, entity map, and how I store the data in the controller: Impersonation Model: class Impersonation extends Entity { public $impersonator_id; public $target_id; public $started_at; public $ended_at;

public function __construct($impersonator_id, $target_id, $started_at, $ended_at = null)
{
    $this->impersonator_id = $impersonator_id;
    $this->target_id = $target_id;
    $this->started_at = Carbon::parse($started_at);
    $this->ended_at = $ended_at ? Carbon::parse($ended_at) : null;
}

} ImpersonationMap: class ImpersonationMap extends EntityMap { protected $table = 'impersonations'; public $timestamps = true;

public function impersonator(Impersonation $impersonation)
{
    return $this->belongsTo($impersonation, User::class, 'impersonator_id', 'id');
}

public function target(Impersonation $impersonation)
{
    return $this->belongsTo($impersonation, User::class, 'target_id', 'id');
}

} Controller: $impersonation = new Impersonation($request->user()->id, $targetUser->id, Carbon::now()); $mapper = Analogue::mapper(Impersonation::class); $mapper->store($impersonation);

Despite the values being valid, both IDs are stored as 0. What could be causing this issue?

0 likes
0 replies

Please or to participate in this conversation.