magento 2 : model in custom module
-
29-01-2021 - |
Question
i already have a table in database also created model files and all works fine so now added another table successfully so what changes i need to do with model files
i mean in model resourcemodel and connection files..
Solution
@Tirth Patel I think you should create separate model as well as Resource file for another db table.
OTHER TIPS
You need to add another resource modal connection (CRUD)
Step : 1 Create Model
app/code/NameSpace/ModuleName/Model/Post.php
Step : 2 Create Resource Model
app/code/NameSpace/ModuleName/Model/ResourceModel/Post.php
Step : 3 Create Resource Model Collection - Get Model Collection
app/code/NameSpace/ModuleName/Model/ResourceModel/Post/Collection.php
After this please run this command line:
php bin/magento setup:upgrade
php bin/magento C:F
do same process for your second table what you have done for your first table. i mean create diffrent model,resource file
for your second table.