[英]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.