2
を使用して選択し、私はeager_load
を使用して特定の列のみを選択しようとしているが、私はそれが私の「選択」をキャンセルするという問題に直面しています。Railsの4 - eager_load
モデル:
class Timeline < ActiveRecord::Base
belongs_to :timeline_category, foreign_key: :timeline_category_id
belongs_to :user, foreign_key: :user_id
scope :with_relations, -> { eager_load(:timeline_category).eager_load(:user).order(created_at: :desc)
end
問合せ:
Timeline.select('timelines.*, users.username, timeline_categories.icon').eager_load(:timeline_category).eager_load(:user)
私も試してみました:何らかの理由で
Timeline.select('timelines.*, users.username, timeline_categories.icon').with_relations
、それはすべての3つのテーブルのすべての列を選択し続けます。どうすれば修正できますか?
でこれらのフィールドを取得し、私は同様の問題を、持っていました私はあなただけのカスタム列を追加することができますが、この方法は、常にそれらのすべてを取得して、あなたは、それらを選択的に取り出すことができない、覚えておいてください。 – potashin