【发布时间】:2023-04-08 08:24:01
【问题描述】:
我有以下型号:
project.rb
has_many :tasks
task.rb
belongs_to :project
has_many :assignments
has_many :users, :through => :assignments
user.rb
has_many :assignments
has_many :tasks, :through => :assignments
assignment.rb
belongs_to :task
belongs_to :user
例如: Project.first.title #=> "曼哈顿" Project.first.tasks.map(&:name) # => ['Find Scientists', 'Find Money', 'Find Location'] Project.first.tasks.first.users.map(&:full_name) #=> ['James Maxwell', 'Evariste Galois', 'Jules Verne']
我的第一个问题是: 我怎样才能找到所有可能带有符号的人的名字来一次触发,我试过了:
Project.first.tasks.users.full_name #=> AND FAILED
Project.first.tasks.map(&:users).full_name #=> AND FAILED
Project.first.tasks.map(&:users).map(&:full_name) #=> AND FAILED
有什么想法吗?
我认为以下问题可能在同一个球场:
如何使用搜索用户任务的“全名”属性的条件来查找项目?
示例
Project.all(:include => {:tasks => :users}, :conditions => ['tasks.users.full_name LIKE ?', query]) #this failed
我认为问题出在“tasks.users”。
谢谢大家,感恩节快乐!
【问题讨论】:
标签: ruby-on-rails activerecord include