i have 2 tables
tickets:
-id
etc..
comments:
-id
-ticket_id
-datetime
etc...
ticket_id is the ticket’s id on which the comment was made.
one ticket can have 0 or more comments in this way
how should i go about creating a relation in my Ticket model, to fetch it’s last comment?
part of my Ticket Model:
class Ticket extends ActiveRecord
{
public function getComments(): ActiveQuery
{
return $this->hasMany(Comment::class, ['ticket_id' => 'id']);
}
public function getHandler(): ActiveQuery
{
return $this->hasOne(User::class, ['id' => 'handler_id']);
}
public function getLastComment()
{
//???
}
}