我正在尝试查找由比变量 min_age 年长的用户制作的所有资产。目前,我正在尝试通过这个电话来做到这一点:
assets = Asset.joins(:user).where("age(users.handles.first.birthday) >= ?", min_age)
每个资产有一个用户,每个用户可以有多个句柄。
class User < ActiveRecord::Base
has_many :handles, :class_name => "UserHandle"
def get_current_age
age(self.handles.first.birthday)
end
这是我得到的错误:
ActiveRecord::StatementInvalid in SearchController#data
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.birthday) >= 90)' at line 1: SELECT `assets`.* FROM `assets` INNER JOIN `users` ON `users`.`id` = `assets`.`user_id` WHERE (age(users.handles.first.birthday) >= 90)
Rails.root: /Users/Jimmy/Documents/Launchpad Toys/LPT_Repositories/orbit-analytics
Application Trace | Framework Trace | Full Trace
app/controllers/search_controller.rb:254:in `find_by_user_current_age'
app/controllers/search_controller.rb:121:in `robot_search'
app/controllers/search_controller.rb:384:in `data'