php - 如何在 OctoberCMS 的联接表中使用 where 子句?
问题描述
我在 Laravel 5 中使用 OctoberCMS。我有几个模型,需要加入它们。
我有“PaymentData”模型和“AppsData”模型。他们都有“mem_id”列,我想根据“PaymentData”模型的数据从“AppsData”模型中获取“app_process”列的值。
我在下面尝试的会导致此错误消息。
“SQLSTATE [42S22]:未找到列:'where 子句'中的 1054 未知列 'app_process'(SQL:选择计数(*)作为聚合 from
BYAPPS_apps_payment_data
wherepay_type
!= 1 andamount
= 0 andapp_process
!= 8)”在 / 的第 664 行主页/ljw/public_html/byapps_cms/vendor/laravel/framework/src/Illuminate/Database/Connection.php
支付数据模型
class PaymentData extends Model
{
use \October\Rain\Database\Traits\Validation;
public $table = 'BYAPPS_apps_payment_data';
public $rules = [
];
public $hasOne = [
'joins' => [
'Jiwon\Byapps\Models\AppsData',
'key' => 'mem_id',
'otherKey' => 'mem_id'
]
];
}
应用数据模型
class AppsData extends Model
{
use \October\Rain\Database\Traits\Validation;
public $table = 'BYAPPS_apps_data';
public $rules = [
];
}
我在 home.htm 中尝试过的内容
use Jiwon\Byapps\Models\AppsData;
use Jiwon\Byapps\Models\PaymentData;
function onGetAppChartData()
{
$this['appsFree'] = PaymentData::where('pay_type', '!=', '1')
->where('amount', '=', '0')
->where('app_process', '!=', '8')
->count();
}
我在这里做错了什么?请有人帮助我...!_!
解决方案
您可以尝试编写这样的自定义查询:
$this['appsFree'] = \DB::table('BYAPPS_apps_payment_data as p')
->join('BYAPPS_apps_data as a', 'a.mem_id', '=', 'p.mem_id')
->where('p.pay_type', '!=', '1')
->where('p.amount', '=', '0')
->where('p.app_process', '!=', '8')
->count();
推荐阅读
- sql - Oracle SQL 存储过程缺少表达式错误
- macos - WinSCP + Wine + MacOSX 打开 MacOS 编辑器可以吗?
- scala - 火花流foreach多个作家
- python - 如何通过将时间戳指定为键值来从字典中获取值。?
- css - grid-template-rows = auto,在自动填充中强制空单元格
- networking - 如何为 Recaptcha 错误解禁我的 IP:“无法联系 reCAPTCHA。检查您的连接并重试。”
- r - 从pdf文本到文档列中文件名的整洁数据框
- visual-studio - Visual Studio 2017 - IDE 黑色部分
- javascript - SonarQube 和 Lcov 报告无法解析文件路径
- classification - Watson Visual Recognition Classifier 需要数小时才能重新训练