Я думаю, что вы, попросите select способ.
User.includes(:profile).limit(10).select(:field1, :field2)
Update:
Ответ от @Hassan woudn't действительно работает. Посмотрите here (нетерпеливого раздел загрузки)
Since only one table is loaded at a time, conditions or orders cannot reference tables other than the main one.
Попробуйте следующее:
class User < ActiveRecord::Base
has_one :profile_w_name, -> { select(:id, :name, :user_id).limit(10) }, class_name: 'Profile'
end
User.includes(:profile_w_name).first.profile_w_name
Не забудьте добавить user_id
поле, так как AR будет пытаться поджать профиль поля.
Update:
Я считаю, лучшее решение для всех выше, после того, как видеть неодобрение жалуется жадную загрузку и SQL фрагмент кода ссылки как select("post.id, comment.post_id")
. Требуется Rails 4.
User.includes(:profile).select(:field1, :field2).references(:profile)
проверка Кроме этого суть, чтобы увидеть разницу https://gist.github.com/astery/6137727
возможный дубликат - HTTP ([Rails 3 выберите с Include?]: // stackoverflow.com/questions/4047833/rails-3-select-with-include) – Benj