Save audit logs with related values

Hello. I have a question: I want to save audit logs in db. When i save model A (a field from model A(integer) have relation “belongs to model B (string)” ) i want to save in audit log related value from model B (string) instead of model A (integer). How can i do that ? I have a code which is saving all values from model A, so the only problem is that i want to save string (from model B) instead integer (from model A)
Sorry for my english :slight_smile:
Greetings
Tom

it depends how you accessing your model b from your model a if you have a relationship declared in your model a to model b you can add a method on model b class which returns your model b data in a format you like better yet you can use __toString on model b and it will convert your model to string when you echo it or store in a varchar/text column

class A extends ActiveRecord
{
    public function getB()
    {
        $this->hasOne(B::class, ['id' => 'b_id']);
    }

    public function saveAuditLog()
    {
         echo $this->getB;
    }

}

class B extends ActiveRecord 
{

    public function __toString()
    {
        return "{$this->column1} -- {$this->column2}";
    }

}