I'm using wbraganca's dynamicform samples codes for mine own project

That is the immediate point where the error has revealed itself. It’s #0 in the stack trace, somewhere in Yii Framework core code. But the real cause of the error is in your code (#10 or #20 in the stack trace, I don’t know) … probably you are handling some variable as Model but it is null in reality.

This error wasn’t from first version of code, we talked via private message and adding relation helped, topic should be closed.

public function getSubcategories()
 return $this->hasMany(Subcategory::className(), ['category_id' => 'id']);

Yes thanks @rafalrudowskisnlb