gpt4 book ai didi

蛋糕PHP 3 : Association property name clashes with field of same name of table

转载 作者:行者123 更新时间:2023-12-03 22:11:54 27 4
gpt4 key购买 nike

我正在使用 CakePHP 3.2。我有两张 table service_requestscoupon_historyservice_requests table

CREATE TABLE `service_requests` (
`id` char(36) NOT NULL,
`request_id` bigint(20) NOT NULL,
`user_id` char(36) NOT NULL,
`user_address_id` char(36) NOT NULL,
`service_id` char(36) NOT NULL,
`service_area_id` char(36) NOT NULL,
`coupon_used` int(11) NOT NULL DEFAULT '0' COMMENT '0: Not Applied; 1: Applied',
`coupon_used_id` char(36) NOT NULL,
`status_code` int(11) NOT NULL,
`status` varchar(50) NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL
)
coupon_history table
CREATE TABLE `coupon_history` (
`id` char(36) NOT NULL,
`user_id` char(36) NOT NULL,
`coupon_id` char(36) NOT NULL,
`service_request_id` char(36) DEFAULT NULL,
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified` datetime NOT NULL
)

当我烤 service_requests表由
bin/cake bake all service_requests

它警告错误为
Association property name "coupon_used" clashes with field of same name of table "service_requests". You should explicitly specify the "propertyName" option. in [/var/www/html/flitfix/admin2/vendor/cakephp/cakephp/src/ORM/Association.php, line 445]

2016-07-01 07:17:32 Warning: Warning (512): Association property name "coupon_used" clashes with field of same name of table "service_requests". You should explicitly specify the "propertyName" option. in [/var/www/html/flitfix/admin2/vendor/cakephp/cakephp/src/ORM/Association.php, line 445]
Trace:
Cake\Error\BaseErrorHandler::handleError() - CORE/src/Error/BaseErrorHandler.php, line 146
Cake\ORM\Association::property() - CORE/src/ORM/Association.php, line 445
Bake\Utility\Model\AssociationFilter::filterAssociations() - ROOT/vendor/cakephp/bake/src/Utility/Model/AssociationFilter.php, line 94
Bake\Shell\Task\TemplateTask::_filteredAssociations() - ROOT/vendor/cakephp/bake/src/Shell/Task/TemplateTask.php, line 465
Bake\Shell\Task\TemplateTask::_loadController() - ROOT/vendor/cakephp/bake/src/Shell/Task/TemplateTask.php, line 295
Bake\Shell\Task\TemplateTask::main() - ROOT/vendor/cakephp/bake/src/Shell/Task/TemplateTask.php, line 147
Bake\Shell\BakeShell::Bake\Shell\{closure}() - ROOT/vendor/cakephp/bake/src/Shell/BakeShell.php, line 252
Cake\Collection\Collection::each() - CORE/src/Collection/CollectionTrait.php, line 51
Bake\Shell\BakeShell::all() - ROOT/vendor/cakephp/bake/src/Shell/BakeShell.php, line 253
Cake\Console\Shell::runCommand() - CORE/src/Console/Shell.php, line 444
Cake\Console\ShellDispatcher::_dispatch() - CORE/src/Console/ShellDispatcher.php, line 221
Cake\Console\ShellDispatcher::dispatch() - CORE/src/Console/ShellDispatcher.php, line 181
Cake\Console\ShellDispatcher::run() - CORE/src/Console/ShellDispatcher.php, line 127
[main] - ROOT/bin/cake.php, line 33

以前有 coupon_used我重命名为 coupon_history 的表并删除所有 controller, model and template命名 coupon_used并尝试再次烘烤 coupon_history但它给出了错误。
我尝试了一个由 Composer 创建的新项目,但也存在同样的错误。

最佳答案

正如警告所说,字段名称“coupon_used”与coupon_useds表属性之间存在冲突,即coupon_used。这是因为 CakePHP 的默认规则。

您应该在 service_requests 表模型中使用另一个名称更改字段名称“coupon_used”或 coupun_useds 表属性。

class ServiceRequests extends Table{
....
//assumption if association is belongsTo
$this->belongsTo('CouponUsed',['propertyName' => 'AnotherCouponUsed']);
....
}

关于蛋糕PHP 3 : Association property name clashes with field of same name of table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38139475/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com