Rail3 '返回 False,除非 XYZ'查询不起作用
在我的 Rails3.1 应用程序中,我尝试在我的订单模型之一中应用以下逻辑。
def digital?
line_items.map { |line_item| return false unless line_item.variant_id = '102586070' }
end
我创建了一个名为 prepaid_voucher 的单独变体,其 id = 102586070。尽管如此,结果是错误的......
订单有很多 line_item
LineItem 属于订单和变式
变体有很多 line_items
这是执行此类任务的最佳方法吗?我该如何修复?
In my rails3.1 application, I'm trying to apply the following logic in one of my order model.
def digital?
line_items.map { |line_item| return false unless line_item.variant_id = '102586070' }
end
I've created a separate variant called prepaid_voucher which has id = 102586070. Despite this, the result is false...
Order has many line_items
LineItem belongs to order and variant
Variant has many line_items
Is this the best way to perform such a task and how can I fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我认为你想要一个双
==
这里line_item.variant_id = '102586070'
,那么我宁愿选择类似的东西(如果我明白你想要什么)但很难理解你真正想要什么,如果找不到 id 的话预期的行为是什么?
First of all I think you want a double
==
hereline_item.variant_id = '102586070'
, then I rather go for something like that (If I understand what you want)But it's hard to understand what you really want, what is the expected behavior if the id is not found?