#1479 suggestion
Bernerd Schaefer

Provide additional options to relationship getters

Reported by Bernerd Schaefer | January 19th, 2011 @ 05:55 AM

Here's a sample use case where this would be invaluable -- being able to specify fields to load on a belongs_to relationship to avoid eager loading data we don't need.

    posts = Post.all

    posts.size # => 842
    posts.user.count # => 840

    posts.each do |post|
      puts "#{post.title}, by #{post.user.name}"
      # This will eager load all user data for all
      # 840 users:
      #   select * from users where user_id in (...)

    # proposal:

    posts.each do |post|
      user = post.user(:fields => :name)
      puts "#{post.title}, by #{user.name}"
      # This will eager load only name (and id) for the users:
      #   select id, name from users where user_id in (...)

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »