0
這裏是我的模型:Rails的嘗試加入3個表
class Template < ActiveRecord::Base
has_many :application_fields
has_many :application_fields_values
end
class ApplicationField < ActiveRecord::Base
belongs_to :template
has_many :application_fields_values
end
class ApplicationFieldsValue < ActiveRecord::Base
belongs_to :application_field
end
以下是我正在努力實現查詢:
SELECT `application_fields_values`.* , `application_fields`.*, `templates`.*
FROM `application_fields_values`
INNER JOIN `application_fields` ON `application_fields`.`id` = `application_fields_values`.`application_field_id`
inner join `templates` on `templates`.`id` = `application_fields`.`template_id`
這裏就是我的了:
@report = ApplicationFieldsValue.joins(:application_field, :template)
但它給了我錯誤:
Association named 'template' was not found; perhaps you misspelled it?
如何使用活動記錄實現上述查詢?
嘗試將名稱複數 – Zippie 2013-04-10 22:54:07
'@ result'應該評估什麼?它應該是ApplicationFieldsValue實例嗎?或者你想要一個來自所有連接表的值的散列? – 2013-04-10 23:10:35
我需要從每個表中的somes值,以便使我的查詢更短,這個問題我只用了所有表。*。 – Catfish 2013-04-11 01:03:08