In general, you can specify which columns you want to select using the .select method, for example:
User.select(:name).where(...)
This will only return values ββfrom the name column. You can associate this with an association, but not with an instance. Thus, since meagar was very aggressive in pointing out that other responses were downvoting (including the Mori remote response), with regard to has_one you cannot associate this with an association (because it is not an association in this case). However, you can create a custom scope, for example:
class Foo < ActiveRecord::Base has_one :bar scope :bar_name, lambda {Bar.select(:name).where(:foo_id=> id)} end
The above is not verified, so you may have to fine-tune it, but overall this approach will allow you to do something like:
foo.bar_name
... without loading all columns from the panel.
source share