Laravel 4中模型的别名

时间:2015-12-17 07:25:24

标签: laravel laravel-4

我正在研究Laravel 4.1。我有4个模型用于四个不同的表,但在这个查询中我试图得到活动,应用程序和查询的计数,因为我正在使用表名的别名,但我不能给模型的别名

任何人都可以解释如何为模型提供别名吗?

return $this->model->select('
      sud.*,
      (select count(saf.userid) 
       from soca_activity_form saf 
       where sud.id = saf.userid  ) activitycount,
      (select count(sa.userid) 
       from soca_applicationform sa 
       where sud.id = sa.userid  ) applicationcount,
      (select count(sqf.userid) 
       from soca_query_form sqf 
       where sud.id = sqf.userid  ) querycount')
->where('admin','!=',1)
->orderBy('id', 'desc')
->paginate(50);

SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册,以便在'。id = saf附近使用正确的语法。userid ) activitycount ,(select count(sauserid) from soca_appli' at line 1 (SQL: select sud . *,(select count(saf { {1}} userid)来自soca_activity_form,其中,有. id = saf . userid)activitycount,(select count(sa . userid)来自soca_applicationform sa,其中sud . id = sa . userid)applicationcount,(从soca_query_form sqf中选择count(sqf . userid),其中sud . id = sqf . userid)querycount . soca_user_details from admin where id`desc limit 50 offset 0)

0 个答案:

没有答案