生成的SQL语句中.TP自动把主表的表名做了别名:live_listing 但是在withCount 生成的统计sql中.却还是使用的主表的完整表名..造成SQL报错.代码贴在下面.哪位大神帮忙看看.是哪里写错了?
model里定义的代码
public function product()
{
return $this->hasMany('LiveProduct','live_listing_id');
}select查询的代码$list = $this->model
->with(['anchor'])
->withCount(['product'])
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();生成的sql语句SELECT
`live_listing`.`id`,
`live_listing`.`anchor_id`,
`live_listing`.`start_time`,
`live_listing`.`end_time`,
`live_listing`.`live_address`,
`live_listing`.`status`,
`live_listing`.`createtime`,
`live_listing`.`updatetime`,
`live_listing`.`delete_time`,
anchor.id AS anchor__id,
anchor. NAME AS anchor__name,
anchor.organ_id AS anchor__organ_id,
anchor.phone AS anchor__phone,
anchor.fans_number AS anchor__fans_number,
anchor.wechat_number AS anchor__wechat_number,
anchor.commission AS anchor__commission,
anchor.create_time AS anchor__create_time,
anchor.update_time AS anchor__update_time,
anchor.delete_time AS anchor__delete_time,
(
SELECT
COUNT(*) AS tp_count
FROM
`mg_live_product`
WHERE
(
(
`live_listing_id` = mg_live_listing.id
)
)
AND `mg_live_product`.`delete_time` IS NULL
LIMIT 1
) AS `product_count`
FROM
`mg_live_listing` `live_listing`
LEFT JOIN `mg_anchor` `anchor` ON `live_listing`.`anchor_id` = `anchor`.`id`
WHERE
`live_listing`.`delete_time` IS NULL
ORDER BY
`live_listing`.`id` DESC
LIMIT 0,
10 最佳答案