Php OcotberCMS-”的英文缩写;SQLSTATE[42S22]:未找到列:1054未知列';用户。应用程序id';
我通过relations收到此错误消息,但我无法找到我需要做什么来停止此错误 我有一个带有控制器和组件的应用程序模型。在后端,我可以添加一个新的应用程序记录。但是为了查看,我得到了错误Php OcotberCMS-”的英文缩写;SQLSTATE[42S22]:未找到列:1054未知列';用户。应用程序id';,php,laravel,eloquent,octobercms,Php,Laravel,Eloquent,Octobercms,我通过relations收到此错误消息,但我无法找到我需要做什么来停止此错误 我有一个带有控制器和组件的应用程序模型。在后端,我可以添加一个新的应用程序记录。但是为了查看,我得到了错误 "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.application_id' in 'where clause' (SQL: select * from `users` where `users`.`deleted_at` is
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.application_id' in 'where clause' (SQL: select * from `users` where `users`.`deleted_at` is null and `users`.`application_id` = 1 and `users`.`application_id` is not null limit 1)" on line 662 of /srv/users/sssandwich/apps/website/public/vendor/laravel/framework/src/Illuminate/Database/Connection.php
我隔离了在的fields.yaml中添加此代码时出现的错误
Acme\Models\Application\fields.yaml
# ===================================
# Form Field Definitions
# ===================================
fields:
client:
label: Client
type: relation
disabled: true
select: concat(name, ' ', surname)
span: left
在
我已经把关系安排好了
/**
* @var array Relations
*/
public $hasOne = [
'client' => ['RainLab\User\Models\User', 'table' => 'users'],
'cv' => ['Acme\Acme\Models\Cv']
];
public $hasMany = [];
public $belongsTo = [
'owner' => ['Backend\Models\User']
];
下面是数据库结构
public function up()
{
Schema::create('acme_acme_applications', function(Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('jobs_id')->nullable()->index();
$table->string('application_id')->nullable()->index();
$table->string('owner_id')->nullable()->index();
$table->string('user_id')->nullable()->index();
$table->string('vacancy_id')->nullable()->index();
$table->string('ref_no', 50)->nullable();
$table->char('status_update')->nullable();
$table->timestamps();
});
}
我有grep'd'application_id',它只出现在数据库结构中。users表是Rainlab用户插件,但我不确定它为什么要在该表中查找应用程序的id
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.application_id'...
我认为这个错误是不言自明的,因为您定义了一对一关系,所以应用程序模型被假定为具有Application\u id
外键
如果应用程序有一个用户,则用户表应包括应用程序id
列:
public $hasOne = [
'client' => [
'RainLab\User\Models\User',
'table' => 'users',
'key' => 'application_id', // the foreign key in User's table
'otherKey' => 'id', // Model record id
],
];
您应该在用户模型中定义反向关系,一个用户belongsTo
public $belongsTo = [
'application' => [
'Acme\Models\Application',
'table' => 'acme_acme_applications',
'key' => 'application_id',
'otherKey' => 'id',
],
];
如果您不想直接编辑RainLab用户的插件(更新过程中会丢失更改),请查看它是如何扩展插件并向数据库中添加多个列的。删除应用程序中的hasOne客户端关系,它看起来好像试图深入太多。谢谢,但是如果我删除hasOne客户端,它将不会显示提交应用程序的用户的姓名。但是我不知道为什么它仍然在寻找应用程序的id。它可能正在尝试拉取应用程序的客户端。尝试将密钥添加到客户端(id作为外键,用户id作为本地密钥)。我不认识格式,所以我不确定你会如何添加它们。
public $belongsTo = [
'application' => [
'Acme\Models\Application',
'table' => 'acme_acme_applications',
'key' => 'application_id',
'otherKey' => 'id',
],
];