更改为Laravel语法后,原始查询不起作用

时间:2019-11-14 11:50:51

标签: laravel

我已将此查询转换为Laravel语法,但不幸的是,尽管vardump中的输出使用的是原始语法,但没有输出。我认为语法有问题:

SQL语法(可以正常工作):

var server = parent.Xrm.Page.context.getClientUrl();

Laravel语法(不起作用):

$word_rec = DB::select( DB::raw("
select distinct
pa.alias 
,p.name_full_formatted
, o.ordered_as_mnemonic 
, c3.event_tag    RET
, c2.event_tag   QTY
, c1.event_tag   CHK

from

CLINICAL_EVENT   C1   
, orders  o
, encounter  e
, person  p
, person_alias  pa
, CLINICAL_EVENT   C2  
, CLINICAL_EVENT   C3  


 where e.person_id = o.person_id
 and p.person_id = o.person_id
 and pa.person_id = p.person_id
and pa.person_alias_type_cd = 10
 and o.order_id = c2.order_id and c2.task_assay_cd = 2622303965
 and o.order_id = c3.order_id and c3.task_assay_cd = 2622303953
 and c1.encntr_id = o.encntr_id and c1.task_assay_cd = 2622303989
")
 );

1 个答案:

答案 0 :(得分:0)

使用Laravel更好的关系使用方式,例如:https://laravel.com/docs/6.x/eloquent-relationships

与使用Model :: with()相比,定义模型并更正关系的功能(一对一,一对多,...)。