如何获取活跃或免费试用用户的产品?(产品属于用户) [英] How to fetch active or free trial users' products? (product belongs_to user)

查看:40
本文介绍了如何获取活跃或免费试用用户的产品?(产品属于用户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

User has_many products

Product belongs_to user

用户的表中还有一个 active_account 和 created_at 列.

User also has an active_account and created_at column in its table.

我正在尝试将其转换为查询:

I am trying to translate this into a query:

如果产品所属的用户拥有有效帐户或使用时间不到 25 天,则存在哪些产品?'

'What products exist where the user that the product belongs to has an active account OR is less than 25 days old?'

这是我到目前为止所拥有的(不确定如何添加不到 25 天的 OR):

This is what I have so far (not sure how to add in the OR less than 25 days old):

Product.joins(:user).where(users: {active_account: true})

推荐答案

试试这个:

 Product.joins(:user).where("users.active_account = ? OR users.created_at >= '#{(Time.now - 25.days).utc.iso8601}'", true)

这篇关于如何获取活跃或免费试用用户的产品?(产品属于用户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆