查找所有在 18 岁之前购买汽车的用户
Find all Users that bought their car before they were 18
我想找到所有在 18 岁之前买车的用户。
我需要这样的查询:
User.includes(:car)
.where(car: { bought_at < (user.birthday + 18.years)})
如何使用 Postgresql 在 Rails5 中编写这样的查询?谢谢
尝试以下
User.includes(:car).where( 'cars.bought_at < ?', user.birthday + 18.years)
确保数据库列 bought_at
和 birthday
是 DateTime
格式。
希望有所帮助
我想找到所有在 18 岁之前买车的用户。
我需要这样的查询:
User.includes(:car)
.where(car: { bought_at < (user.birthday + 18.years)})
如何使用 Postgresql 在 Rails5 中编写这样的查询?谢谢
尝试以下
User.includes(:car).where( 'cars.bought_at < ?', user.birthday + 18.years)
确保数据库列 bought_at
和 birthday
是 DateTime
格式。
希望有所帮助