[英]How can I use where clause in the joined tables in OctoberCMS?
我将Laravel 5与OctoberCMS一起使用。我有几种模型,需要将它们加入。
我有“ PaymentData”模型和“ AppsData”模型。 他们都有“ mem_id”列,我想基于“ PaymentData”模型的数据从“ AppsData”模型中获取“ app_process”列的值。
我在下面尝试的操作会导致此错误消息。
“ SQLSTATE [42S22]:找不到列:1054'where子句'中的未知列'app_process'(SQL:从
BYAPPS_apps_payment_data
中选择count(*)作为聚合,其中pay_type
!= 1且amount
= 0且app_process
!= 8)” /home/ljw/public_html/byapps_cms/vendor/laravel/framework/src/Illuminate/Database/Connection.php的第664行
PaymentData模型
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'
]
];
}
AppsData模型
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.