Skip to content

Commit 5c664e3

Browse files
committed
[Fix] crud template not working because primary field name was not matching
1 parent 47fa502 commit 5c664e3

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

templates/crud/Ui/Component/Form/${Entityname}/DataProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class DataProvider extends AbstractDataProvider
3131
/**
3232
* Construct
3333
*
34-
* @param $name
35-
* @param $primaryFieldName
36-
* @param $requestFieldName
34+
* @param string $name
35+
* @param string $primaryFieldName
36+
* @param string $requestFieldName
3737
* @param Collection $collection
3838
* @param FilterPool $filterPool
3939
* @param array $meta

templates/model/Model/${Simpleentityname}.php renamed to templates/model/Model/${Entityname}.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* ${Simpleentityname}.php
4+
* ${Entityname}.php
55
*
66
* @copyright Copyright © ${commentsYear} ${CommentsCompanyName}. All rights reserved.
77
* @author ${commentsUserEmail}
@@ -12,24 +12,24 @@
1212
use Magento\Framework\DataObject\IdentityInterface;
1313
use Magento\Framework\Model\AbstractModel;
1414

15-
class ${Simpleentityname} extends AbstractModel implements IdentityInterface
15+
class ${Entityname} extends AbstractModel implements IdentityInterface
1616
{
1717
/**
1818
* CMS page cache tag
1919
*/
20-
const CACHE_TAG = '${vendorname}_${modulename}_${simpleentityname}';
20+
const CACHE_TAG = '${vendorname}_${modulename}_${entityname}';
2121

2222
/**
2323
* @var string
2424
*/
25-
protected $_cacheTag = '${vendorname}_${modulename}_${simpleentityname}';
25+
protected $_cacheTag = '${vendorname}_${modulename}_${entityname}';
2626

2727
/**
2828
* Prefix of model events names
2929
*
3030
* @var string
3131
*/
32-
protected $_eventPrefix = '${vendorname}_${modulename}_${simpleentityname}';
32+
protected $_eventPrefix = '${vendorname}_${modulename}_${entityname}';
3333

3434
/**
3535
* Initialize resource model
@@ -39,7 +39,7 @@ class ${Simpleentityname} extends AbstractModel implements IdentityInterface
3939
protected function _construct()
4040
{
4141
parent::_construct();
42-
$this->_init('${Vendorname}\${Modulename}\Model\ResourceModel\${Simpleentityname}');
42+
$this->_init('${Vendorname}\${Modulename}\Model\ResourceModel\${Entityname}');
4343
}
4444

4545
/**
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* ${Simpleentityname}.php
4+
* ${Entityname}.php
55
*
66
* @copyright Copyright © ${commentsYear} ${CommentsCompanyName}. All rights reserved.
77
* @author ${commentsUserEmail}
@@ -10,7 +10,7 @@
1010

1111
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
1212

13-
class ${Simpleentityname} extends AbstractDb
13+
class ${Entityname} extends AbstractDb
1414
{
1515
/**
1616
* Initialize resource model
@@ -19,6 +19,6 @@ class ${Simpleentityname} extends AbstractDb
1919
*/
2020
protected function _construct()
2121
{
22-
$this->_init('${vendorname}_${modulename}_${simpleentityname}', 'id');
22+
$this->_init('${vendorname}_${modulename}_${entityname}', 'entity_id');
2323
}
2424
}

templates/model/Model/ResourceModel/${Simpleentityname}/Collection.php renamed to templates/model/Model/ResourceModel/${Entityname}/Collection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @copyright Copyright © ${commentsYear} ${CommentsCompanyName}. All rights reserved.
66
* @author ${commentsUserEmail}
77
*/
8-
namespace ${Vendorname}\${Modulename}\Model\ResourceModel\${Simpleentityname};
8+
namespace ${Vendorname}\${Modulename}\Model\ResourceModel\${Entityname};
99

1010
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
1111

@@ -14,7 +14,7 @@ class Collection extends AbstractCollection
1414
/**
1515
* @var string
1616
*/
17-
protected $_idFieldName = 'id';
17+
protected $_idFieldName = 'entity_id';
1818

1919
/**
2020
* Define resource model
@@ -23,6 +23,6 @@ class Collection extends AbstractCollection
2323
*/
2424
protected function _construct()
2525
{
26-
$this->_init('${Vendorname}\${Modulename}\Model\${Simpleentityname}', '${Vendorname}\${Modulename}\Model\ResourceModel\${Simpleentityname}');
26+
$this->_init('${Vendorname}\${Modulename}\Model\${Entityname}', '${Vendorname}\${Modulename}\Model\ResourceModel\${Entityname}');
2727
}
2828
}

templates/model/Setup/InstallSchema.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,32 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
2828
$setup->startSetup();
2929

3030
/**
31-
* Create table '${vendorname}_${modulename}_${simpleentityname}'
31+
* Create table '${vendorname}_${modulename}_${entityname}'
3232
*/
3333
$table = $setup->getConnection()->newTable(
34-
$setup->getTable('${vendorname}_${modulename}_${simpleentityname}')
34+
$setup->getTable('${vendorname}_${modulename}_${entityname}')
3535
)->addColumn(
36-
'id',
36+
'entity_id',
3737
Table::TYPE_SMALLINT,
3838
null,
3939
['identity' => true, 'nullable' => false, 'primary' => true],
40-
'${Simpleentityname} ID'
40+
'${Entityname} ID'
4141
)->addColumn(
4242
'identifier',
4343
Table::TYPE_TEXT,
4444
100,
4545
['nullable' => false],
46-
'${Simpleentityname} Identifier'
46+
'${Entityname} Identifier'
4747
)->addIndex(
4848
$setup->getIdxName(
49-
$setup->getTable('${vendorname}_${modulename}_${simpleentityname}'),
49+
$setup->getTable('${vendorname}_${modulename}_${entityname}'),
5050
['identifier'],
5151
AdapterInterface::INDEX_TYPE_FULLTEXT
5252
),
5353
['identifier'],
5454
['type' => AdapterInterface::INDEX_TYPE_FULLTEXT]
5555
)->setComment(
56-
'${Simpleentityname} Table'
56+
'${Entityname} Table'
5757
);
5858

5959
// Add more columns here

templates/model/Setup/Uninstall.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function uninstall(SchemaSetupInterface $setup, ModuleContextInterface $c
2222
{
2323
$setup->startSetup();
2424

25-
if ($setup->tableExists('${vendorname}_${modulename}_${simpleentityname}')) {
26-
$setup->getConnection()->dropTable($setup->getTable('${vendorname}_${modulename}_${simpleentityname}'));
25+
if ($setup->tableExists('${vendorname}_${modulename}_${entityname}')) {
26+
$setup->getConnection()->dropTable($setup->getTable('${vendorname}_${modulename}_${entityname}'));
2727
}
2828

2929
$setup->endSetup();

0 commit comments

Comments
 (0)