Allowing the selection of which fields to read when lazy loading an object by reference

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • 3.1.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      When iterating over a collection (and not using eager loading), if you only have a a few information to display on a referenced object, it is a waste to load the entire object every time.

      Example:

      Project.where(:admin_type => true).each do |p|

      puts p.user.email

      end

      Is really not optimized, in order to do load only the email field from the user one must write this:
      User.where(:_id => p.user_id).only(:email).first.email

      But this is not really nice to write and does not use the nice syntaxe.

      It would be great to have a mechanism similar to: p.user.only(:email).email

            Assignee:
            Unassigned
            Reporter:
            Alexandre Ponsin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: