使用Rails 3.0.7,并具有以下4种型号:
class User < ActiveRecord::Base
end
class Administrator < User
has_and_belongs_to_many :clients
end
class Client < ActiveRecord::Base
has_and_belongs_to_many :administrators
has_and_belongs_to_many :meetings
end
class Meeting < ActiveRecord::Base
has_and_belongs_to_many :clients
def self.foo
self.joins(:clients => :administrators)
end
end
呼叫:
Meeting.foo.to_sql
生产:
SELECT meetings.*
FROM meetings
INNER JOIN clients_meetings ON clients_meetings.event_id = meetings.id
INNER JOIN clients ON clients.id = clients_meetings.child_id
INNER JOIN clients_administrators ON clients_administrators.child_id = clients.id
INNER JOIN users ON users.type = 'Administrator'
但似乎错过了"clients_administrators"one_answers"users"之间的最终联接关系。我认为SQL的最后一行应该是:
INNER JOIN users ON users.id = clients_administrators.user_id
WHERE users.type = 'Administrator'
这是个虫子吗?或者我误解了什么?
感谢
这似乎是一个错误,但它已在Rails3.1中得到解决。