0
查詢生成器定製我要地圖教義的條款
select
address.*,
(CASE WHEN (customer.default_billing_address_id = address.id) THEN 1 ELSE 0 END) as isDefaultBillingAddress,
(CASE WHEN (customer.default_shipping_address_id = address.id) THEN 1 ELSE 0 END) as isDefaultShippingAddress
from
s_user customer
join
s_user_attributes customerattributes on customerattributes.customer_number = customer.customernumber
join
s_user_addresses address on address.user_id = customer.id
where customerattributes.userID = 214
下面的SQL語句但是,當我寫了我的教訓查詢與查詢生成器,我總是得到查詢有一點不同:
[...]
FROM s_user_addresses s1_
[...]
INNER JOIN s_user_attributes s5_ ON s0_.id = s5_.userID
INNER JOIN s_user s0_ ON s0_.id = s5_.userID
AND (s5_.customer_number = s0_.customernumber)
WHERE s5_.userID = 214
ORDER BY sclr_0 DESC
,sclr_1 DESC
最後這是使用查詢生成器的代碼:
$builder->from(Address::class, 'address')
->andWhere('customerAttribute.customerId = :userId')
->setParameter('userId', $userId)
->join('address.customer', 'customer')
->join('customer.attribute', 'customerAttribute', Join::WITH, 'customerAttribute.customerNumber = customer.number')
->addSelect([
'(CASE WHEN (customer.defaultBillingAddress = address.id) THEN 1 ELSE 0 END) as HIDDEN isDefaultBillingAddress',
'(CASE WHEN (customer.defaultShippingAddress = address.id) THEN 1 ELSE 0 END) as HIDDEN isDefaultShippingAddress',
])
->addOrderBy('isDefaultBillingAddress', 'DESC')
->addOrderBy('isDefaultShippingAddress', 'DESC');
的問題是,該JOIN
子句得到一個AND
,我只想被加入而不是id的
爲什麼'和'而不是'哪裏'? – JustOnUnderMillions
@JustOnUnderMillions不應該有所作爲。 –
@Fabian Picone那麼不需要兩種方法,或者? – JustOnUnderMillions