TimestampBehavior::class, 'createdAtAttribute' => 'applied_in', 'updatedAtAttribute' => false, ], ]; } public function getAccount(): ActiveQuery { return $this->hasOne(Account::class, ['id' => 'account_id']); } /** * Find the username after the current of the account. * * @param int $afterTime * @return UsernameHistory|null */ public function findNextOwnerUsername(int $afterTime = null): ?self { return self::find() ->andWhere(['account_id' => $this->account_id]) ->andWhere(['>', 'applied_in', $afterTime ?: $this->applied_in]) ->orderBy(['applied_in' => SORT_ASC]) ->one(); } }