public function index()
{
if ($this->request->isAjax())
{
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['yangyinorderstudent'])
->with(['testlocaion'])
->with(['getordergeocity'])
->where($where)
->where('order.state','in','3,4,5,6,8')
->order($sort, $order)
->count();
$list = $this->model
->with(['yangyinorderstudent'])
->with(['testlocaion'])
->with(['getordergeocity'])
->where($where)
->where('order.state','in','3,4,5,6,8')
->order($sort, $order)
->limit($offset, $limit)
->select();
$list= collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
order模型关联使用了setEagerlyType(0);发现生成的sql语句是错误的 public function yangyinorderstudent()
{
return $this->hasOne('orderStudent','order_id','id')->setEagerlyType(0);
}
public function testlocaion()
{
return $this->hasOne('testLocation','id','test_location_id')->setEagerlyType(0);;
}
public function getordergeocity()
{
return $this->hasOne('geoCity','id','geo_city_id')->setEagerlyType(0);
}
sql语句中的field会被多次拼接sql语句中如下:
SELECT
`order`.ORDER.ORDER.id,
`order`.ORDER.ORDER.order_number,
`order`.ORDER.ORDER.user_id,
`order`.ORDER.ORDER.created_time,
`order`.ORDER.ORDER.updated_time,
`order`.ORDER.ORDER.expire_time,
`order`.ORDER.ORDER.state,
`order`.ORDER.ORDER.amount,
`order`.ORDER.ORDER.postage,
`order`.ORDER.ORDER.subject_info_id,
`order`.ORDER.ORDER.subject_info_name,
`order`.ORDER.ORDER.subject_level_id,
`order`.ORDER.ORDER.subject_level_level,
`order`.ORDER.ORDER.tutorial_id,
`order`.ORDER.ORDER.tutorial_ti
`order`.ORDER.ORDER.test_location_status,
`order`.ORDER.ORDER.test_location_id,
`order`.ORDER.ORDER.payment_type,
`order`.ORDER.ORDER.payment_status,
`order`.ORDER.ORDER.payment_transaction_no,
`order`.ORDER.ORDER.payment_time,
`order`.ORDER.ORDER.video_uploaded,
`order`.ORDER.ORDER.video_file,
`order`.ORDER.ORDER.face_verification_system_result,
`order`.ORDER.ORDER.face_verification_score,
`order`.ORDER.ORDER.face_verification_result,
`order`.ORDER.ORDER.examiner_assign_status,
`order`.ORDER.ORDER.examiner_id,
`order`.ORDER.ORDER.examiner_review,
`order`.ORDER.ORDER.examiner_score,
`order`.ORDER.ORDER.examiner_result,
`order`.ORDER.ORDER.examiner_comment,
`order`.ORDER.ORDER.admin_comment,
`order`.ORDER.ORDER.admin_flag,
`order`.ORDER.ORDER.hidden,
`order`.ORDER.ORDER.removed,
`order`.ORDER.ORDER.note,
`order`.ORDER.ORDER.basic_cert_status,
`order`.ORDER.ORDER.basic_cert_require_level,
`order`.ORDER.ORDER.certificate_status,
`order`.ORDER.ORDER.reconciliation_flag,
`order`.ORDER.ORDER.refund_status,
`order`.ORDER.ORDER.blacklist_flag,
`order`.ORDER.ORDER.tip,
`order`.ORDER.ORDER.logistic_company,
`order`.ORDER.ORDER.logistic_tracking_number,
`order`.ORDER.ORDER.assgined_time,
`order`.ORDER.ORDER.promo_code,
`order`.ORDER.ORDER.geo_city_id,
`order`.ORDER.ORDER.source,
ORDER.ORDER.yangyinorderstudent.order_id AS yangyinorderstudent__order_id,
ORDER.ORDER.yangyinorderstudent.NAME AS yangyinorderstudent__name,
ORDER.ORDER.yangyinorderstudent.photo_file AS yangyinorderstudent__photo_file,
ORDER.ORDER.yangyinorderstudent.sex AS yangyinorderstudent__sex,
ORDER.ORDER.yangyinorderstudent.birthday AS yangyinorderstudent__birthday,
ORDER.ORDER.yangyinorderstudent.ethnicity_id AS yangyinorderstudent__ethnicity_id,
ORDER.ORDER.yangyinorderstudent.identity_type AS yangyinorderstudent__identity_type,
ORDER.ORDER.yangyinorderstudent.identity_number AS yangyinorderstudent__identity_number,
ORDER.ORDER.yangyinorderstudent.identity_photo AS yangyinorderstudent__identity_photo,
ORDER.ORDER.yangyinorderstudent.email AS yangyinorderstudent__email,
ORDER.ORDER.yangyinorderstudent.self_study AS yangyinorderstudent__self_study,
ORDER.ORDER.yangyinorderstudent.learn_time AS yangyinorderstudent__learn_time,
ORDER.ORDER.yangyinorderstudent.school_name AS yangyinorderstudent__school_name,
ORDER.ORDER.yangyinorderstudent.play_teacher_name AS yangyinorderstudent__play_teacher_name,
ORDER.ORDER.yangyinorderstudent.play_teacher_phone AS yangyinorderstudent__play_teacher_phone,
ORDER.ORDER.yangyinorderstudent.contact_user AS yangyinorderstudent__contact_user,
ORDER.ORDER.yangyinorderstudent.contact_mobile AS yangyinorderstudent__contact_mobile,
ORDER.ORDER.yangyinorderstudent.contact_phone AS yangyinorderstudent__contact_phone,
ORDER.ORDER.yangyinorderstudent.province_id AS yangyinorderstudent__province_id,
ORDER.ORDER.yangyinorderstudent.city_id AS yangyinorderstudent__city_id,
ORDER.ORDER.yangyinorderstudent.area_id AS yangyinorderstudent__area_id,
ORDER.ORDER.yangyinorderstudent.address AS yangyinorderstudent__address,
ORDER.testLocation.id AS testLocation__id,
ORDER.testLocation.city_id AS testLocation__city_id,
ORDER.testLocation.NAME AS testLocation__name,
ORDER.testLocation.desc
ORDER.testLocation.address AS testLocation__address,
ORDER.testLocation.valid AS testLocation__valid,
ORDER.testLocation.removed AS testLocation__removed,
ORDER.testLocation.created_time AS testLocation__created_time,
ORDER.testLocation.updated_time AS testLocation__updated_time,
ORDER.testLocation.created_system_user_id AS testLocation__created_system_user_id,
ORDER.testLocation.updated_system_user_id AS testLocation__updated_system_user_id,
ORDER.testLocation.sort AS testLocation__sort,
getOrderGeoCity.id AS getOrderGeoCity__id,
getOrderGeoCity.province AS getOrderGeoCity__province,
getOrderGeoCity.NAME AS getOrderGeoCity__name,
getOrderGeoCity.enabled AS getOrderGeoCity__enabled,
getOrderGeoCity.basic_cert_option AS getOrderGeoCity__basic_cert_option,
getOrderGeoCity.locator_city AS getOrderGeoCity__locator_city
FROM
`order` `order`
INNER JOIN `order_student` `yangyinorderstudent` ON `order`.`id` = `yangyinorderstudent`.`order_id`
INNER JOIN `test_location` `testLocation` ON `order`.`test_location_id` = `testLocation`.`id`
INNER JOIN `geo_city` `getOrderGeoCity` ON `order`.`geo_city_id` = `getOrderGeoCity`.`id`
WHERE
`order`.`state` IN ( '3', '4', '5', '6', '8' )
ORDER BY
`order`.`id` DESC
LIMIT 0,
10
最佳答案
