Magento – Magento 2 Insert Data into custom table using Collection Factory

magento2

I am following tutorials at http://alanstorm.com/magento_2_crud_models_for_database_access/ for creating my extension but theres one key part of that tutorial that appears to be out of date.

This Part :

$todo = $this->toDoFactory->create();
$todo->setData('item_text','Finish my Magento article')
->save();

SetData and Save no longer work this way.

So how can I use a Collection Factory to create a new item in my table?

Best Answer

Nevermind, I figured it out.

First you would do $this->toDoFactory->create()->getNewEmptyItem(); And then continue on with setting data and saving.