首页 \ 问答 \ Query Builder自定义on子句(Query Builder custom on clause)

Query Builder自定义on子句(Query Builder custom on clause)

我想用doctrine映射以下SQL语句

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

但是当我用查询构建器编写我的doctrine查询时,我总是得到一个不同的查询:

[...]
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 ,我只想要customer_number加入而不是id


I want to map the following SQL statement with doctrine

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

But when I write my doctrine query with the query builder I always get the query a little different:

[...]
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

And finally this is the code that uses the query builder:

$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');

The problem is, that the JOIN clause gets an AND, I just want that the customer_number gets joined not the id's


原文:https://stackoverflow.com/questions/43207925
更新时间:2022-10-07 15:10

最满意答案

无边落木萧萧下 不尽长江滚滚来

相关问答

更多
  • 1.老师用计算机教我们画画。 2.小马和小牛爱吃草。 3.叶子一片片从树上落下来。 4.我们的小学堂最漂亮。
  • 如果你是北方城市,叶面喷水这一项就要省去,北方天气不如南方,南方湿热,叶面的水很快会蒸发掉,北方则不同,进入深秋入冬时节,温度过低,叶面重复积水很快会发黄,干枯。还有一点秋冬季节交替时青苹果在北方城市易发生受冻现象。此时更不能叶面喷水。叶面喷水可以选择温度较高的季节。
  • 万物生梵文版的歌词是经咒“金刚萨埵百字明”。 “空手把锄头,步行骑水牛,人从桥上过,桥流水不流。”如果你能够明白傅大士的这首偈语,也就能明白汉文版歌词的意思了。 类似的歌曲有萨顶顶的《神香》、《陀罗尼》、《妈妈天哪》、齐豫的《大悲咒》、《心经》、《大吉祥天女咒》、朱哲琴的《阿姐鼓》。
  • 问题表明S是图中顶点V的子集。 可能存在非叶节点。 但是,您必须确保这些内部节点不在S中。如果S等于V,那么您就是对的。 The question states that S is a subset of the vertices V in the graph. There may be non-leaf nodes. However, you have to make sure that these internal nodes are not in S. If S would be equal to V ...
  • 你的解释基本上是归纳的证明,所以是的,我会说它是“合法的”。 关于我们何时拥有单个根的第一条评论是基本案例。 然后给定属性所在的二叉搜索树,您可以解释在通过添加一个节点修改树之后,该属性仍然成立。 这就是归纳步骤。 Your explanation is basically a proof by induction, so yes, I would say that it is 'legit'. Your first comment about when we have a single root is t ...
  • 考虑通过细分叶节点来扩展四叉树。 该叶节点成为内部节点(将叶数减少一个),并添加四个叶节点。 如果先前的内部节点数是N,则新的内部节点数是N + 1,并且叶的数量是1 + 3 * N-1 + 4 = 1 + 3 *(N + 1)。 一般声明遵循归纳。 Consider expanding a quadtree by subdividing a leaf node. That leaf node becomes an internal node (decreasing the leaf count by on ...
  • 一种选择是找到两个节点中最不共同的祖先,以及从每个节点到达该祖先的节点序列。 这是算法的草图: 从每个节点开始,向后走到该节点的父节点,直到到达根节点。 计算从每个节点到根的路径上的节点数。 设第一节点的高度为h 1 ,第二节点的高度为h 2 。 设h = min(h 1 ,h 2 )。 这是两个节点中较高者的高度。 从每个节点开始,继续跟随节点的父指针,直到两个节点都处于高度h。 记录在此步骤中您遵循的节点。 此时,两个节点都处于相同的高度。 在找到公共节点之前,请继续从每个节点向上行进到其父节点。 最终 ...
  • “将这些字符串保存在树外的数组中。” 评论:你确定你必须存储字符串吗? 如果只是存储整数并在递归完成后创建字符串,那就更清晰了。 好的,无论如何(并且没有给出源代码)你只是: 在开始递归之前创建一个足够大的(*)数组 创建一个指针,用于写入数组的不同部分,将该指针初始化为数组的开头。 将指针指向您的递归作为新的/附加函数参数。 每次在递归中到达一片叶子你 写入你在叶子上找到的指针 增加指针(你可以这样做,因为你有指针指针 "save these strings in an array outside of ...
  • 编辑:我刚看到你可能有一棵有根的树。 您可以创建树的DFS,并且从当前节点开始,您没有边缘到与父节点不同的节点,那么您已经找到了一个叶子。 引用维基百科 : 图中顶点的度数是入射到它的边的数量。 孤立的顶点是零度的顶点; 也就是说,一个不是任何边缘端点的顶点。 叶顶点(也是悬垂顶点)是一度的顶点。 只计算每个节点的程度。 如果它是1那么你有一片叶子。 Edit: I have just seen you probably have a rooted tree. You can make a DFS of t ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)